Create a Horizontal Line with Text Using Pure HTML CSS

When you want to create a horizontal line to separate sections or content in HTML, CSS plays a vital role. This is particularly useful when you want to include text within that line, such as a title or label, to enhance the visual appeal andlegibility of your content. In this article, we will explore how to create an HTML and CSS horizontal line with text.

an image of a computer screen with some type of text in the bottom right corner
an image of a computer screen with some type of text in the bottom right corner

Let's begin by understanding the basic concept of a horizontal line in HTML. By default, HTML5 provides a


tag for creating horizontal lines, which is quite straightforward. However, this doesn't allow for any text within the line. To create a horizontal line with text, we'll need to use a combination of HTML and CSS.

✨ The <hr> Tag – Horizontal Rule
✨ The <hr> Tag – Horizontal Rule

Using CSS to Design Horizontal Line with Text

To design a horizontal line with text, we need to apply CSS to a regular HTML element. A common practice is to use an element like

and style it to behave like a horizontal line with text.

CSS Text With Video Background
CSS Text With Video Background

Let's dive into the details of implementing this. Below is a simple example:

Single Horizontal Line with Text

HR with centered text
HR with centered text

To create a horizontal line with text, we can use CSS to style a

element. We set the height and background color properties to achieve the line effect, and use CSS text properties to place the text within the line.

```html

Your Text
```

Multiple Horizontal Lines with Text

If you want to create multiple horizontal lines with text, you can simply repeat the structure we created above. In this case, using loops in your code is more practical and less redundant.

css border
css border

```html {% for text in text_list %}

{{ text }}
{% endfor %} ```

Styling Horizontal Line with Text

Basic styling of the horizontal line is easy to perform. You can change the background color, width, and height of the line. You can also customize the font, color, and size of the text.

Changing Line and Text Colors

an image of the back side of a computer screen with text that reads, add css to html
an image of the back side of a computer screen with text that reads, add css to html

To change the line color, simply replace the value of the 'background' property in the 'div' styling. As for the text color, adjust the 'color' property in 'span' styling.

Adjusting Line and Text Width

the css border radius is shown in black and white, with text below it
the css border radius is shown in black and white, with text below it
the css shorthand background is shown in purple, blue and green colors with text below it
the css shorthand background is shown in purple, blue and green colors with text below it
How to center align text horizontally and vertically in CSS
How to center align text horizontally and vertically in CSS
Highlight Text CSS: 7 Cool CSS Highlight Text Effects - Coding Dude
Highlight Text CSS: 7 Cool CSS Highlight Text Effects - Coding Dude
the words are displayed in red and black on a dark background that is lit up
the words are displayed in red and black on a dark background that is lit up
an image of a computer screen with the text css 4 2 written below it
an image of a computer screen with the text css 4 2 written below it
how to create css custom text underline
how to create css custom text underline
using HTML and CSS create a beautiful flower #codet #htmlcss #project #code #programmer #codinglife
using HTML and CSS create a beautiful flower #codet #htmlcss #project #code #programmer #codinglife
Space, Line Break, and Tags in HTML Content
Space, Line Break, and Tags in HTML Content
CSS Notes for Beginners (Easy + Quick Guide) 🎨
CSS Notes for Beginners (Easy + Quick Guide) 🎨
3 Ways To Create Rainbow Text In HTML CSS
3 Ways To Create Rainbow Text In HTML CSS
CSS Gradient Card Border Animation
CSS Gradient Card Border Animation
Coding a Stylish Blog Design Layout in HTML & CSS
Coding a Stylish Blog Design Layout in HTML & CSS
How to Create Scrolling Text With CSS [+ Code Examples]
How to Create Scrolling Text With CSS [+ Code Examples]
CSS line behind title text
CSS line behind title text
an image with the text how to place text over image in html css
an image with the text how to place text over image in html css
an image of a computer screen with some text on it
an image of a computer screen with some text on it
HTML CSS Responsive Text Without Using Media Queries
HTML CSS Responsive Text Without Using Media Queries
how to create faded background in css for web developer
how to create faded background in css for web developer
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes

To adjust the width of the line, you can set the 'width' property in the 'div' styling. For the text width, you need to adjust the 'padding' property in the 'span' styling.

Adjusting Line and Text Height

To adjust the height of the line, you can adjust the 'height' property in the 'div' styling. For the text height, you should adjust the 'line-height' property or 'font-size' in the 'span' styling.

With these ideas, you should be well-equipped to create an HTML and CSS horizontal line with text. This allows you to add an elegant and professional touch to your website's design. It's a small detail, but often small details make the biggest difference, especially in web design. So, go ahead and experiment with different styles to make your website truly unique!

Related Articles

W3 Html Horizontal Line Html And Css Buttons Display Text On Mouseover For Image In Html W3schools W3schools Html Download File W3schools Divs Css Head Html Link W3schools Html And Css Basics Quiz Automatic Image Slider In Html Css W3schools W3schools Html Datetime W3 Html Div