Make a line in css. Horizontal lines

While creating HTML pages design plays a significant role. Especially when we are talking about various symbols and decorative design: these little things help make the “language” of your page more accessible and clear, and also significantly change its perception and appearance generally. One of the most important elements for design is the horizontal line, and then we will learn in more detail how to work with it and how to make a horizontal line in html.

What is a horizontal line and what is it for?

A horizontal line in html is a page design element that performs a number of functions:

  1. Decorative. Helps add attractiveness to the page.
  2. Dividing. Promotes the effective separation of information of different meanings.
  3. Highlighting or emphasizing. Draws the attention of page guests to the necessary and most important information.

It is the horizontal line that is considered the most in an accessible way to implement a range of functions. It is very simple to create, and in appearance it looks very profitable. By simple changes to the html code you can adjust:

  • length;
  • width;
  • color characteristics;
  • alignment along one edge or the other.

It is worth noting that the horizontal line refers to block elements. This means that it occupies a new line on the page, and the text that follows it will go below.

Creating a Horizontal Line in HTML

You can set a line using a simple tag – hr in triangular brackets. It is short for "Horizontal Rule" and defines the classic external parameters. It differs from many others in that it does not need a closing tag and is able to exist independently. Change external characteristics element using additional values ​​in the tag:

  1. Length. If you do not want the length of the line to extend over the entire page, then you can set the desired size in pixels or percentages. This is done for help additional word“width” in the tag and a numeric length indicated after the “=” sign in quotes.

It looks like this. For example, if we need a length of 100 pixels, we set the following tag: hr width=”100″

  1. Alignment. Alignment is possible to the left or right edges, and also to the center. This characteristic only works if you have already specified the width parameter, since a line that spans the entire page cannot be aligned. For alignment, we set an additional attribute in the “align” tag and add a direction to it: center – for central, left – for left and right – for right alignment.

The finished tag in this case will look like this. For example, if we need to set the center alignment for a horizontal line 150 pixels long, then the finished tag will look like this: hr align=”center” width=”150″.

Note that "align", the alignment metric, is placed in 1st place, even though the attribute is dependent on the width metric.

  1. Width. You can also choose to specify the width, creating a bold or thin underline. This criterion does not depend on anything and can be used as an independent criterion without specifying length or alignment. For it, we use the size attribute in the tag and a numeric value equal to the desired width in pixels. The number is indicated in quotation marks after the size attribute and the “=” symbol.

Thus, if we need to create a line with a width of 15 pixels, we need to create the following tag: hr size=”15″.

  1. Color. It is also specified as an independent indicator. To change it use color attribute in combination with the name of the color in the form of a code either on English language. The color is indicated in quotation marks after the “=” symbol.

So the tag for the standard line is white can be written in two ways: hr color=”#FFFFFF” or hr color=”white”

Black can be created using the code #000000.

  1. Put away shadow. If you need an element that does not contain a shadow, then you should use the noshade attribute in the tag. It can be used alone or in combination with other elements. A tag for a standard line using it will look like this: hr noshade

Creating a Horizontal Line Using Video

And if you want to receive information in a more visual format, then refer to the following video, which describes in detail the possibilities of working with a horizontal line.

Having determined the required dimensions of the horizontal line, you can design the website pages in such a way that the information is structured and visually competent. This helps visitors more easily perceive the information presented and makes your site stand out from others.

Task

Make a horizontal line on the page.

Solution

Horizontal lines are good for separating one block of text from another. Small text with horizontal lines at the top and bottom attracts more reader attention than regular text.

Using a tag


you can draw a horizontal line, the appearance of which depends on the attributes used, as well as the browser. The tag is a block element, so the line always starts with new line, and after it all elements are displayed on next line. Thanks to the many tag attributes
the line created through this tag is easy to manage. If you also connect the power of styles, then adding a line to a document becomes a simple task.

Default line


displayed gray and with a volume effect. This type of line does not always suit the site design, so the desire of developers to change the color and other parameters of the line through styles is understandable. However, browsers have mixed approaches to this issue, which is why you will have to use several style properties at once. In particular, older versions of the browser Internet Explorer For line color, use the color property, and other browsers use background-color . But that's not all, you must specify the line thickness ( height property ) nonzero and remove the border around the line by setting the border property to none. Putting all the properties together for the hr selector, we get universal solution For

popular browsers

(example 1).

Example 1: Horizontal line


HTML5 CSS 2.1 IE Cr Op Sa Fx


Horizontal line color Text string Result

this example

shown in Fig. 1. Rice. 1. Colored horizontal line To emphasize some especially important elements site, it would not hurt to use all kinds of CSS styles and properties. Of course, you don’t have to bother too much with the text and highlight it, for example, in bold or italics, change the background or make a frame around the text. But one of the presented methods is not always suitable. Let's say you have a text that needs to be divided due to the specifics of its semantic load. This is where they come to

HTML help

and CSS properties. How to make a line in text using CSS To implement our plans, we will need to contact style.css file, having written in it the corresponding property

- border– a horizontal line located above the text;

- border-right– a vertical line located to the right of the text;

- border-bottom– a horizontal line located below the text;

- border-left– vertical line located on the left.

How to make a line in html

Using CSS properties you can enter all the necessary values ​​by editing the HTML code. To do this, you need to go to the administrative part of the site. Select one of the published materials, switch text editor into HTML code editing mode and add CSS properties. A sample can be seen below.



How to make a dotted or straight line?



By specifying these properties, will you be able to emphasize the importance of the material being presented, paragraph or heading?


Brief description of commands

- width– line length;

- solid- solid line;

- dotted– dotted line.

For a deeper understanding of styles, I recommend reading this one.

It is necessary to understand that in the process of making changes to the site code, the properties that determine the type of line, its thickness and color are listed separated by a space.

This method has several advantages:

A wide range of possibilities with which you can make almost any line.

Ease of making all necessary changes directly to the HTML code. This greatly simplifies the task for inexperienced site builders.

How to make a straight horizontal line using an HTML tag

The first thing I would like to draw your attention to is that this tag, despite all the subtleties and principles of html, does not have a closing tag. It can be used anywhere html code, between tags And.

Tag attributes

- width– is responsible for the length of the line. Can be specified either as a percentage or in pixels.

- size– line thickness. Specified in pixels.

- color– defines the color of the line.

- align– an attribute responsible for line alignment. In turn, the team relates to him.