Possibilities of formatting text information in html. HTML formatting tags. CSS formatting rules

As you know, the main content of Web pages is still text. With the rare exception of special gallery sites. So it's no surprise that HTML has so many different controls for displaying text.

In fact, in order to display a text string in the browser viewport, No tags are required: You just need to write the text itself. But when you need to break it down at least into paragraphs, here you need to use tags. The fact is that in various computer systems different characters are used to break text into paragraphs, and HTML documents should always be displayed the same way on a wide variety of computer platforms. Therefore, I had to introduce tags for paragraphs.

At the beginning of each paragraph, a tag is placed <р> and at the end, the closing tag ... At the same time, the tag naturally has some parameters. These include already known to us common parameters identification class and id, styling parameter style, which we will consider in the second chapter, and the alignment parameter align... We should talk a little more about the last parameter.

In HTML, the term "alignment" refers to both the horizontal and vertical positioning of an element. But in the case of paragraphs of text, it makes sense to talk only about horizontal alignment or, as it is also called, "justification".

Justification allows you to nest a paragraph to the left or right of the browser viewport, center it, or stretch words so that the text evenly fills the entire width of its allotted space. For these purposes, the values \u200b\u200bare used left, right, center and justify, respectively. Let's consider their application on the example of another HTML document.

Listing 1.4

"http://www.w3.org/TR/html4/striet.dtd"\u003e


Horizontal alignment a63atsev


A paragraph aligned to the left
<р align="right">A paragraph pressed to the right edge
<р align="center">Centered paragraph

The paragraph stretched across the width

The result of viewing a file with this code using the Internet Explorer browser is shown in Fig. 1.4. As you can see, the last paragraph, which, according to our code, should have been stretched in width, is displayed by the browser Internet Explorer just like the first one. This case is a prime example of how different browsers interpret HTML code. In our case, Internet Explorer simply ignored the unknown parameter, using the default display option.

Figure: 1.4. The browser window showing the result of the file shown in Listing 1.4

Sometimes, in order to further separate one paragraph from another, web page builders try to use empty paragraphs, that is, there is nothing between the start and end paragraphs. According to the spec, browsers should simply ignore such constructs. Therefore, to separate paragraphs or force a line break within one paragraph, use the tag
... This is a directive tag. It simply marks the place where you want to move the display to another line. An example of using this tag to accomplish both of these goals is shown in an example HTML document, whose code is shown in Listing 1.5.

Listing 1.5

"http://www.w3.org/TR/html4/strict.dtd"\u003e
.

Force line breaks


<р>The paragraph that we
Forcibly ripped
<р>Next paragraph

<р>Paragraph after a forced break

And how this file looks when viewed using a browser is shown in Fig. 1.5.

Figure: 1.5. Browser window showing the result of displaying the file shown in Listing 1.5

Tag
in addition to universal identification parameters, it also has the parameter clearwhich is used to more accurately align text when it flows around an object, for example graphic imageembedded in a Web page. One of four predefined parameters can be used as the value of this parameter. keywords: none, left, right, all.

The default value of none indicates that the next line will start where it would have started without using this parameter, under normal circumstances. Value leftmeans that the next line will start at the left margin of the object wrapped around the text. If you need to use the right margin for these purposes, then you should use the value right... And the value alltells the browser to use both the left and right margins of the object, so that the text is displayed as compactly as possible.

Now let's move on to considering the font design of the text. Anywhere in the paragraph, we can use the tag with some set of parameters that will determine appearance the font that will be used to display the text after this tag. The termination of this tag is done with its closing pair .

Tag possesses the following inherent parameters: sizeused to specify the size of the font to be applied, color - to set the color of the characters in the font, and facewhich specifies which font will be used to display the text. Let's take a look at these parameters.

As we just said, the size parameter is used to specify the size of the characters of the font used. The values \u200b\u200bfor this parameter are numbers from one to seven. They indicate a certain relative size of characters. The fact is that in HTML you cannot set the absolute size of characters in points, as we are used to doing in ordinary office applications. The user will view the Web page on their computer, and we do not know in advance what fonts they may have installed and what sizes are available. Therefore, we can only specify the relative font size, and the user's browser will select the most appropriate size.

Also, as the value of the size parameter, we can specify and change the font size. For example, to increase the font size one level, use the following construction:

And to reduce the size of characters by two levels, the following code is applied:

However, to use such structures, it is necessary to build on a certain basic size. To set this size, the tag is used with the same parameter size... If this tag is not used, then the third level will be used as the base character size. Here's an example of using these tags.

Listing 1.6.

"http://www.w3.org/TR/html4/stcict.dtd"\u003e


Sivol size</tit1е> <br> </head><br> <body><br> <p><font sizе=*7">Seventh size</font></p><br> <p><font sizе="6">Sixth dimension</font></p><br> <pxfont sizе="5">Fifth size</font></p><br> <pxfont sizе="4">Fourth size</font></p><br> <pxfont sizе="3">Third size</font></p><br> <p><font sizе="2">Second size</font></p><br> <p><font size="l">First size</font></p><br> <p><basefont size=2x font size="+2">Size offset</font></p><br> </body> <br> </html> </i></p><p><img src='https://i0.wp.com/tepka.ru/html4b/6.jpg' height="524" width="455" loading=lazy></p> <p>Figure: 1.6. <i>Browser window displaying the file shown in Listing 1.6</i></p> <p>But we have considered using only one attribute of the tag <i> < font > </i>... The next step is the procedure for setting the color of the characters of the font used. We already know that the parameter is used for this <i>color</i>... We talked about how to write down the designation of a particular color in the previous section, that is, we just have to give an example. So, to set the green color of the symbols of the font used, you should use the following construction:</p> <p><i><font color="green"> </i></p> <p>And the last parameter we are considering <i>face</i> allows you to set the type of font used, that is, we can specify that the text should be displayed, say, using the font Times New Roman or Copperplate Gothic. However, here it should be understood that the user's browser will display the text using the fonts installed in the operating system of the remote user, and if we use some rare font to make the text content of the Web page more expressive, then it may not be in the user's system. In this case, the browser will use its own font rules.</p><p>Each browser has a settings section in which the user specifies which fonts to use for the text content of the loaded Web pages. Therefore, as the parameter value <i>face</i> a comma-separated list of font names is applied. The browser tries to find them on its system in the order in which they are listed, and the first font that matches is used to display the text. Now that we know the order of using all the parameters of the tag <i><font> </i>, here's an example of their common use:</p> <p><i><font size=4 color="black" face="Courier New, Arial Black"> </i></p><p>With this tag, we declare that the text after it will be displayed in the fourth size, the characters will be black, and the font should be Courier New or, if not installed on the system, Arial Black.</p><p>But when creating ordinary text documents, we are not satisfied with one indication of the size, color and type of font. There are also different weights of the same font. We can make characters italic, bold, underlined and strikethrough. HTML also provides us with these capabilities. So, all in turn.</p> <ul><li>Tag <i> <b> </i> with closing pair <i></b> </i> creates bold characters in the selected font.</li> <li>Tags <i> <i> </i> and <i></i> </i> frame italic characters.</li> <li>Tag <i><u> </i> and <i></u> </i> force the browser to underline text between them</li> <li>Tag <i><strike> </i> with its closing pair <i></strike> </i>create strikethrough text.</li> <li>Tags <i><tt> </i>and <i></tt> </i> frame the characters that the browser displays in monospaced font.</li> <li>Tags <i><small> </i> and <i></small> </i> indicate that the text between them should be displayed in a reduced size font.</li> <li>Tags <i><big> </i>and <i></big> </i>on the contrary, they increase the size of the characters in between.</li> </ul><p>Naturally, we cannot do without an example.</p> <p>Listing 1.7.</p> <p><i> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"<br> "htfcp: //www.w3.org/TR/html4/strict.dtdH\u003e <br> <html> <br> <head><br> <title> Outlines of symbols


Text happens bold or italic

Or maybe at the same time bold and italic
<р>it happens underlined and nepeckled.
<Р>or monospaced .
<р>We can increase and reduce size of characters.

As you can see from the example, we can combine different styles with each other. But you should be careful in the order of the tags. The start and end tags must both be nested like a case in other tags that were previously applied. An example of this can be seen in the tenth line of the listing. And how this HTML document looks when viewed with a browser is shown in Fig. 1.7.

We've looked at the ways in which you can set various options for displaying text. However, HTML provides several basic ways of displaying text, which do not need to be specified with a whole set of tags. For them, their own tags are allocated, that is, certain categories of text are defined, which are displayed in a predefined way. All of these categories are most commonly used in the scientific and computer industries. Let's list them.

  • A term is highlighted in the text using a pair of tags<еm> and.
  • A "boosted" highlight designed to grab attention even more is created using the tag and its covering twin.
  • Using tags and indicates that the text between them is a quote.
  • The definition of a certain term is highlighted with tags and.
  • Pair of tags and is used to highlight source code in a programming language.
  • Text information displayed by the program is formatted using tags AND.
  • User-entered text is indicated by tags and... P Variables in source code programs are designated using a pair of tags and.
  • Tags and highlight abbreviations.
  • And well-established letter combinations that are not abbreviations, that is, acronyms, are highlighted with tags and.

However, it is not enough to know the names of tags, you still need to clearly understand how they design the text. And here one cannot do without an example.

Figure: 1.7. The browser window showing the result of the file shown in Listing 1.7

Listing 1.8

"http://www.w3.org/TR/html4/strict.dtd"\u003e


Standard display options

This is plain text
<р>it<еm>excretion... AND More noticeable selection


<р>it quote And this definition.


<р>We can write program code, text, by the user,
output text and non-variable
<р>This is how<аbbr>abbreviations... And so -<аcronum>acronyms .


The result of displaying such an HTML document is shown in Fig. 1.8.

Figure: 1.8. The browser window showing the result of the file shown in Listing 1.8

Very often it becomes necessary to place on a Web page a text prepared in advance using a text editor that has already formatted the text on its own. In this case, the format of the text, its hyphenation and placement directly depend on the length of the line in characters, which was set in this text editor... If you place text on a Web page using conventional means, this formatting will naturally be broken. Therefore, a custom tag was introduced for such preformatted fragments. This tag<рrе> has a width parameter, the value of which is the length of the string in characters. Naturally, it is advisable to force the installation of exactly the font that was used to format the text before using this tag. So, to insert the preformatted text, we can use the following piece of code:

text.

IN this example we specify that the text should be displayed assuming that the string is sixty characters long. At the same time, the rules for "collapsing spaces" do not apply in the preformatted text either. The fact is that when a browser encounters several consecutive spaces in the normal text of a Web page, it collapses them into one space. And preformatted text does not undergo such a transformation, which allows you to preserve its formatting, which in the simplest text editors is carried out using white space characters. In HTML, by the way, the tab character is also considered a whitespace character.

It should also be noted that HTML provides the ability to display upper quotation marks using tags, which are usually used to highlight direct speech and some quotes. A tag is provided for quotes with its final twin ... And to frame direct speech, tags are usually used and... Moreover, the tag has the cite parameter, the value of which is the network address, also called the URL, of the Internet resource on which the quoted text was originally located. And together with the tag usually the lang parameter is used, the value of which is the code designation of the language, according to the punctuation rules of which the bounding quotes are placed. It's no secret that in different languages \u200b\u200bit is customary to use different quotation marks.

Also worth mentioning is the problem of hyphenation. Typically, Web page builders don't even think about this problem, and browsers don't bother with paginated word wrapping. If the word does not fit on the line, it simply wraps to another line. But this is not the only correct way to display text. A situation may well arise when you need to display text using hyphenation. HTML provides two types of hyphenation - explicit and the so-called "soft". Explicit hyphenation is created using an en dash character, usually replaced by numeric text substitutions "-" However, explicit hyphenation is inconvenient because when the browser viewport is resized, the line length may change, and the hyphenation still remains visible. Even if it is in the middle of the line. Therefore, most often they still use "soft" hyphenation. They are created using the "-" text substitution. At the same time, soft hyphenation characters are not visible in the text, and only if any word in which these characters were inserted does not fit entirely in the line, it is wrapped with a breakdown into syllables, according to the inserted "soft" hyphens. And only one of the soft hyphenation symbols in this word becomes visible.

Also, HTML with its tags allows you to display superscripts and subscripts. A couple of tags are used to create a superscript and, and the subscript must be tagged and... Let's look at an example of using these tags.

Listing 1.9

"http://www.w3.org/TR/html4/strict.dtd"\u003e


Bepx subscripts

<р>Water is H 20


<р>The ratio of mass and energy - E \u003d mc 2



How the browser renders the indexes is shown in Fig. 1.9.

Figure: 1.9. The browser window showing the result of displaying the file in Listing 1.9

Also to text design refers to the horizontal lines that often separate significant portions of the textual content of Web pages. A line is inserted into the text of an HTML document using a tag


... The tag has several parameters that allow you to fine-tune the appearance of the horizontal line.

The align parameter allows you to specify the horizontal alignment of the line. The parameter can have one of three preset values: left, right and center, which press the horizontal line to the left or right edge of the viewport, or center it, respectively. The default is center. If the tag


the noshade parameter is included, then the displayed horizontal line will not have a shadow. And the last one width parameter allows you to set the length of the horizontal line. The default is "100%". And the line height in pixels is set using the size parameter. Let's look at the application of all these parameters using an example.

Listing 1.10





<р>This is a regular line displayed by default.



<р>This is a shortened line pressed to the left


<р>This is a shortened center line


<р>This is a shortened line pressed to the right


<р>This is a thickened line without shadow


What a similar HTML document looks like when viewed with a browser is shown in Fig. 1.10.

And on this, perhaps, we can end the consideration of the possibilities of text formatting inherent in HTML.

Figure: 1.10. Browser window showing the result of displaying the file in Listing 1.10

To give it a certain style, you need to place the text in the appropriate container.

All formatting tags can be divided into three groups:

1. Header tags ( h1-h6).

2. Tags for the design of the main text ( , , ,

, 
 etc.).

3. Grouping tags (

,


,
)

Header tags

Turns regular text into a heading of a certain level. Tag

creates a first level heading - the largest and most important (usually the title of the article on the page),
responsible for the heading of the sixth level - the smallest and most inconspicuous. These tags are important to both users and search engines - subheadings are loved by both. The hierarchy of levels must be observed, that is, for

have to go

, and not vice versa.

To understand how this works, enter the following code in the html file:

First level heading

Second level heading

Third level heading

Fourth level heading

Level 5 heading
Sixth level heading

It will look like this in the browser:

Body Text Decoration Tags

Allows formatting at the character level. Let's consider what you can do with them.

Bold font

Needed to focus on the text. It is also important for search engines, they can highlight keywords.

Responsible for the bold type of tags and .

Superscript and subscript

They can be used in formulas, equations, designation of some quantities.

The tag is responsible for creating subscripts , for the top ones the tag is used .

X 1\u003d 32 m 2

Reducing size

If you need to make the text one less than the set throughout the page, then you need to use the tag

Plain text. Reduced text.

Underline

This type of highlight can be used to indicate changes made to a document or simply to draw attention to the text.

Plain text. Underlined text.

Strikethrough

You can cross out the information if it has already lost its relevance. The tag is intended for this .

Italics

It is needed to focus attention on the text, and can be created with a tag or .

Entering computer text

It happens that you need to add the source code of the program and the results of its work to a web page. To make it easy to distinguish visually different parts of the text from each other, HTML developers have implemented tags of this group.

Into container the program code is enclosed, while its variables are marked with a tag and the execution result is ... Container contains text that the user must enter from the keyboard when working with the program, and everything that is enclosed in tags

, retains the original format, including extra spaces and line breaks.

in this way a, b, c, here program execution result , and this is user entered text

displayed like this
.

Quotes and definitions

The program code will look like in this way , variables are designated as follows: a, b, c , here program execution result , and this is user entered text ... Retaining original formatting

displayed like this 
.

Quote in the blockquote tag.
Quote inside cite container.Short quote with q tag.Highlighted definition.Abbreviation (NGO, IP).

General example

To better understand what tag is responsible for and how it works, look at the following code and the result of its execution.

Fatty text can be made with tags strong and b... Behind italics answer em and i.

Tags sub and sup used to create lower (x 1... x n) and upper (42\u003d 16) indices. Del crosses out, ins - emphasizes.

Tags code, kbd, var and samp rarely used and needed to display program listing

abbr is needed to denote abbreviations ( Html). The blockquote, cite and q tags are used to style quotes ( Already the sky was breathing in autumn)

The pre tag retains the original text formatting without removing spaces or line breaks.

The browser interprets this code like this:

Grouping tags

We need the text not to go in one continuous line, but to be broken into logical components.

  • The tags contain a paragraph.

First paragraph

Second paragraph

  • Tag
    moves to the next line within a paragraph (there will be no indentation before the line).

  • lets you draw a horizontal line. You can use it to separate text more clearly. Attributes width, size, color, align and noshade set the width, thickness, color, alignment, and no 3D effect of the line, respectively.

Line above line.


Line below the line.

Table of contents:

Hello dear blog readers. In the last article I looked at block tags for structuring text. And today we will consider registration html text-pages, i.e. Consider tags that will help highlight important pieces of text in order to attract the attention of visitors. We will also learn how to insert special characters into the page.

Selection of fragments of text. Strong and em tags.

Most important hTML tool used to highlight important fragments of text is tag ... It makes the text bold. The tag can also make text in bold. ... Though tags and are similar in their action, but they are not equivalent. Tag is a physical markup tag and just sets the text to bold. AND is a logical markup tag and marks the importance of the selected text. Tag is more important when search engine optimization the site and its contents carry more weight to search engines.

For italic selections of text fragments are applied tags and ... The content of these tags is drawn at an angle to simulate a handwritten font.
When developing websites, tags are often used to highlight text and than tags and ... Example of using tags , , and for text formatting:

Html (from the English. HyperText Markup Language - "hypertext markup language"; pronounced h-ti-em-el) - standard document markup language in The world wide web.

And it looks like this:

Let's apply tags and on our page from previous articles:

A site about cars.


Welcome to our car website. Here you will find many interesting and useful articles about cars, about their technical characteristics and features.


Scientific language car this is:


Mechanical motor trackless road vehicle with at least 4 wheels .




Car classification


Cars are of the following types:



  • Passenger;

  • Cargo;

  • SUV;

  • Buggy;

  • Pickup;

  • Sports;

  • Racing.

Result:

Except elements , , and there are many tags in HTML to style the text of an html document. I quote short list such tags:

  • - Abbreviation... displayed underlined in the browser by default;
  • - Acronym... In contrast to the abbreviation, it stands for an established abbreviation. Displayed underlined;
  • - small quote, displayed in italics;
  • - a fragment of the program source code, displayed in monospaced font;
  • - marks the text, remote from a web page, displayed strikethrough;
  • - means new term in a document, displayed in italics;
  • - used to highlight text that has been added to new version the document is displayed underlined;
  • - used to highlight data entered from the keyboardor for key names, displayed in monospaced font;
  • - used to highlight quotes, the content is automatically quoted;
  • - denotes data output by any program, displayed in monospaced font;
  • - actually the same as , only is a physical markup tag, and - logical. displayed in monospaced font;
  • - selection variable name in the source code of the program, displayed in italics.

And this is how they are displayed in the browser:

Line break

As we learned from previous articles, block elements are used to translate strings, in particular the tag

Highlighting paragraph.

Let's put copyright information on our web page:

All rights reserved. year 2013.


A site about cars.

Result:

And as we can see the lines are separated by too large a distance, as if they have nothing to do with each other. In this case, it is better to use tag
... This tag sets line breakbut unlike the tag

Does not indent the line. Let's apply the tag
on our page:

All rights reserved. year 2013.
A site about cars.

Much better this way:

Therefore, in some cases, when formatting text html page don't forget about the tag
.

Insert special characters. Literals.

Sometimes you need to insert a special character into a web page, for example, such characters:<, >, ©. To insert special characters HTML uses literals. Is a sequence of characters that starts with the character & and ends with the character ; , and between them is a sequence of letters - character code... So for inserting symbols<, >, © the following literals are used respectively:<, &rt; и.

All rights reserved. year 2013.
A site about cars.

Now the page looks really cool:


Below are the names of the most commonly used symbols:

    Non-breaking space -

  • Left double quote - “

    Left angle quotation mark - "

    Left apostrophe - '

    Right apostrophe - '

    Right double quote - "

    Right angle quotation mark - & raquo.

A special place among these symbols is occupied by the "non-breaking space". If it is necessary that the hyphenation is not performed in some place of the text line, then insert a "non-breaking space" there. In addition to the non-breaking space literal, you can use paired tag . The nobr tag notifies the browser to display text without hyphenation. However, the use of this tag can lead to the appearance of a horizontal scroll bar in the browser window and the user will have to scroll the text horizontally to see it in full, which is very inconvenient. Also, this tag is not part of the HTML specification, which leads to invalid code. Therefore, I advise you to use this tag only as a last resort when decorating the text of the html page.

HTML also allows you to insert any character that is supported by the Unicode encoding. For this, a literal with the following structure is used: <код символа>; ... You can find out the code of the desired symbol either on the Internet, or you can use the utility "Table of symbols"shipped with Windows. You can run it like this: "Start-\u003e All Programs-\u003e Accessories-\u003e System Tools-\u003e Symbol Table" or press WIN + R and type in the window execute charmap. The Symbol Table window appears.

If you select a character in the list of symbols that cannot be entered from the keyboard, an inscription of the form will appear on the left side of the status line "Key: Alt +<код символа>". Take this character code and insert it into the literal. For example, let's insert the © symbol into our page using the symbol code. We select this symbol in the “Symbols table” and in the status bar on the left side we see the inscription “Key: Alt + 0169”. We take the code "0169" and in our web page, instead of the literal, insert © :

All rights reserved. © year 2013.
A site about cars.

And we make sure that everything is displayed correctly on the page.

That's it for today. As always, I'll summarize:

    for line break apply without indentation tag
    ;

    and to insert special characters use literals kind: &<имя символа>; or &<код символа> .

In the next article I will tell you how to insert pictures into a page, so I advise

HTML tags - the basis of the HTML language. Tags are used to delimit the beginning and end of elements in markup.

Each HTML document consists of a tree of HTML elements and text. Each HTML element is identified by a start (opening) and end (closing) tag. The start and end tags contain the tag name.

All HTML elements are divided into five types:

  • empty elements , ,
    , , ,
    , , ,
    Used for storage additional information about the page. This information is used by browsers to process the page, and search engines - to index it. In the block there may be multiple tags , since, depending on the attributes used, they carry different information. Measurement indicator in the specified range.