Skip to main content
PHP Blog

Back to all posts

How to Add A Line Under A Header In HTML?

Published on
5 min read
How to Add A Line Under A Header In HTML? image

Best HTML Tools to Buy in October 2025

1 Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece

Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece

  • COMPLETE 20-PIECE KIT FOR VERSATILE ELECTRONIC REPAIRS AND DISASSEMBLY.

  • DURABLE STAINLESS STEEL SPUDGERS ENSURE LONG-LASTING, RELIABLE USE.

  • INCLUDES ESSENTIAL TOOLS FOR EASY SCREEN REPLACEMENT AND CLEANING.

BUY & SAVE
$9.99 $11.89
Save 16%
Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece
2 Web Design with HTML, CSS, JavaScript and jQuery Set

Web Design with HTML, CSS, JavaScript and jQuery Set

  • TWO-BOOK SET COMBINES ESSENTIAL WEB DESIGN TECHNOLOGIES SEAMLESSLY.
  • HIGHLY VISUAL FORMAT ENHANCES LEARNING FOR BEGINNERS AND PROS ALIKE.
  • ACCESSIBLE LANGUAGE MAKES COMPLEX CONCEPTS EASY TO GRASP QUICKLY.
BUY & SAVE
$36.19 $58.00
Save 38%
Web Design with HTML, CSS, JavaScript and jQuery Set
3 iFixit Jimmy - Ultimate Electronics Prying & Opening Tool

iFixit Jimmy - Ultimate Electronics Prying & Opening Tool

  • THIN STEEL BLADE: EFFORTLESSLY TACKLES TIGHT GAPS AND CORNERS.
  • ERGONOMIC HANDLE: ENSURES PRECISE CONTROL DURING REPAIRS.
  • UNIVERSAL TOOL: PERFECT FOR TECH, HOME PROJECTS, AND DIY TASKS.
BUY & SAVE
$7.95
iFixit Jimmy - Ultimate Electronics Prying & Opening Tool
4 HTML and CSS: Design and Build Websites

HTML and CSS: Design and Build Websites

  • MASTER HTML & CSS TO CREATE STUNNING, RESPONSIVE WEBSITES!
  • SECURE PACKAGING ENSURES SAFE DELIVERY EVERY TIME.
  • PERFECT GIFT CHOICE FOR BUDDING WEB DESIGNERS!
BUY & SAVE
$12.88 $29.99
Save 57%
HTML and CSS: Design and Build Websites
5 HTML 5: A QuickStudy Laminated Reference Guide

HTML 5: A QuickStudy Laminated Reference Guide

BUY & SAVE
$7.95
HTML 5: A QuickStudy Laminated Reference Guide
6 HTML and CSS QuickStart Guide: The Simplified Beginners Guide to Developing a Strong Coding Foundation, Building Responsive Websites, and Mastering the ... (Coding & Programming - QuickStart Guides)

HTML and CSS QuickStart Guide: The Simplified Beginners Guide to Developing a Strong Coding Foundation, Building Responsive Websites, and Mastering the ... (Coding & Programming - QuickStart Guides)

BUY & SAVE
$21.24
HTML and CSS QuickStart Guide: The Simplified Beginners Guide to Developing a Strong Coding Foundation, Building Responsive Websites, and Mastering the ... (Coding & Programming - QuickStart Guides)
+
ONE MORE?

To add a line under a header in HTML, you can use the <hr> tag. <hr> stands for horizontal rule and represents a thematic break or separation between content. Here's how you can add a line under a header in HTML:

In this example, the <h1> element represents the header text, and the <hr> tag adds a horizontal line directly below it. The line will stretch across the full width of its container.

You can also customize the appearance of the line using CSS. For example, to make the line thicker and change its color, you can apply CSS styles:

HTML:

CSS:

.custom-line { border-color: red; /* Change the line color */ border-width: 3px; /* Change the line thickness */ }

By specifying a class for the <hr> tag and applying corresponding CSS rules, you can achieve the desired visual effect for the line under the header.

Are there any specific HTML tags for adding a line under a header?

No, there are no specific HTML tags for adding a line under a header. However, you can achieve this effect using CSS by adding a border-bottom style to the header element. Here's an example:

HTML:

CSS:

.header { border-bottom: 1px solid black; }

This CSS rule adds a 1-pixel solid black line at the bottom of the header element.

Are there any accessibility considerations when adding a line under a header?

Yes, there are several accessibility considerations to keep in mind when adding a line under a header:

  1. Color contrast: Ensure that there is sufficient contrast between the header text and the line beneath it. This helps users with visual impairments to easily distinguish the header and the line. Follow the Web Content Accessibility Guidelines (WCAG) recommended color contrast ratios.

  2. Text alternatives: Provide a descriptive alternative text for the header and the line. Alternative text is read aloud by screen readers, allowing users with visual impairments to understand the content. Make sure the description accurately represents the purpose of both the header and the line.

  3. Semantic markup: Use appropriate HTML markup for both the header and the line. Headers should be marked up using

    to

    tags based on their hierarchical importance. The line can be marked up using

    (horizontal rule) or

    with appropriate accessibility attributes.

  4. Keyboard navigation: Make sure that keyboard users can easily navigate to the header and line. Ensure that they can reach the header using the "tab" key and that the line doesn't interrupt or create navigation barriers.

  5. Screen reader compatibility: Test the header and line with screen readers to ensure they are properly announced and rendered. Screen reader users should be able to understand the purpose and association between the header and the line.

  6. Responsive design: Consider how the line beneath the header behaves on different screen sizes. Ensure that it remains visible and accessible for users on smaller devices or with different viewports.

By addressing these considerations, you can improve the accessibility of the header and line for users with disabilities and provide a better user experience for all.

How can the line under a header be positioned relative to the header itself?

The line under a header can be positioned relative to the header itself using various CSS properties. Here are a few common methods:

  1. Borders: You can use the CSS border-bottom property to create a line under the header. For example, you can set border-bottom: 1px solid black; to create a 1 pixel solid black line under the header.
  2. Pseudo-elements: You can use CSS pseudo-elements like ::after or ::before to create a line under the header. By positioning these pseudo-elements below the header using CSS properties like content and position, you can achieve the desired effect. For example:

.header::after { content: ""; display: block; width: 100%; border-bottom: 1px solid black; position: absolute; bottom: -5px; }

  1. Box shadows: You can also use the box-shadow property to create a line effect under the header. By giving the shadow a vertical offset and adjusting its size and color, you can simulate a line. For example:

.header { box-shadow: 0px 5px 5px -5px black; }

These are just a few examples, and there are many other ways to position a line under a header relative to the header itself. The choice of method depends on the specific design and requirements of your project.

Can the line under a header be responsive and adapt to different screen sizes?

Yes, the line under a header can be made responsive and adapt to different screen sizes. This can be achieved by using CSS media queries, which allow different styles to be applied based on the screen size or device being used. By adjusting the width, height, and positioning of the line, it can resize and reposition itself accordingly to maintain its appearance across different screen sizes.