-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e502116
commit a6a47f1
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
content/notes/stop-using-thematic-break-to-design-horizontal-line.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
draft: false | ||
locale: en | ||
date: 2023-06-01T04:38:32.569Z | ||
title: Stop using the <hr> tag to design a horizontal line! | ||
description: It's sometimes easy to forget that UI doesn't dicated semantics. In this article I'll show you how to use the <hr> tag properly. | ||
author: David Dias | ||
tags: | ||
- coding | ||
- hr | ||
- html | ||
- semantic | ||
type: note | ||
--- | ||
|
||
I have seen way too many times people using the `<hr>` HTML element, which is called "thematic break" instead of CSS. | ||
|
||
Using the HTML <hr> tag purely for designing horizontal lines is an incorrect practice. | ||
The real purpose of the <hr> tag is to denote a thematic break in the content (like between paragraphs), not just to visually create a horizontal rule. | ||
|
||
If you need a decorative line, CSS is a more appropriate choice. | ||
|
||
For instance: | ||
|
||
```html | ||
<div class="styled-line"></div> | ||
``` | ||
|
||
Example CSS: | ||
|
||
```css | ||
.styled-line { | ||
border-bottom: 1px solid #000; | ||
margin: 1em 0; | ||
} | ||
``` | ||
|
||
In terms of accessibility, using <hr> as a design element can confuse screen reader users, as it indicates a "thematic break". | ||
|
||
Semantics are important, not only for accessibility but also for SEO. So, please, stop using the <hr> tag to design a horizontal line! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters