HTML <del> Tag: Usage, Attributes, and Practical Examples

By Cristian G. Guasch •  Updated: 09/25/23 •  9 min read

If you’re diving into the world of HTML, you’ve likely come across various tags and elements that shape your web content. One such intriguing tag is the HTML <del> tag. This handy element allows developers like me to represent text that’s been deleted from a document, introducing an interactive aspect to web pages.

Understanding how to use this tag effectively can make all the difference in creating dynamic content. It’s not just about marking up deleted text, but also signaling changes or updates to users in real time. The <del> tag keeps track of what was there before, providing context for any alterations made.

So let’s get our hands dirty with the HTML <del> tag: its usage, attributes, and some examples that’ll bring it all home. By exploring this underutilized tool together, we can maximize your toolkit and enhance your website’s user experience journey along the way!

Understanding the HTML <del> Tag

Let’s dive right into the HTML <del> tag. This useful piece of code denotes text that has been deleted from a document. It’s like using a virtual strikethrough on your webpage, crossing out words or phrases to show they’re no longer relevant.

Here’s how you’d typically use it:

<p>The price of the product was <del>$50</del>.</p>

In this example, “$50” is shown as crossed out. This can come in handy when you need to show price reductions, revisions, or outdated information.

Now, what about attributes? The <del> tag supports global attributes – those common to all HTML elements – and event attributes. But one attribute specific to this tag is cite. This points to a URL where the reason for deletion can be found. Here’s an example:

<del cite="http://example.com/reason-for-deletion">Deleted text</del>

Keep in mind that not all browsers will display this citation link.

One common mistake I’ve seen folks make is thinking the <del> tag only applies visually; it doesn’t affect SEO or accessibility. In truth, search engine bots pay attention to these tags too! Similarly, screen readers may treat them differently based on user settings.

Lastly, don’t confuse the <del> tag with its sibling – ‘<s>‘. While both produce a line through text visually, they have different semantics: <s> marks content no longer accurate or relevant without implying it was deleted. So choose wisely!

Remembering these nuances about the HTML <del> tag can help ensure your web pages are not just aesthetically pleasing but also semantically correct and accessible!

Key Attributes of the HTML <del> Tag

Let me tell you, the HTML <del> tag is a pretty nifty tool to have in your web development arsenal. It’s used for striking through text, indicating that the enclosed content has been deleted or replaced in a document. But beyond its basic function, what really makes this tag stand out are its key attributes.

Now, I’ll be honest with you – the <del> tag isn’t overloaded with attributes. In fact, it has just two: cite and datetime. But don’t let their number fool you; these two are more than enough to make your markup shine.

The cite attribute is used to specify the URL of the resource where the deletion was made or explained. This could be a different webpage or even a specific section within your current document. Here’s an example of how it can be utilized:

<del cite="https://example.com/deletions">This text has been deleted.</del>

Next up we’ve got our second contender – datetime. Now this one’s all about timing. It indicates when exactly the deletion occurred. The value should be written in ISO date format (YYYY-MM-DD). Let’s take a look at how this works:

<del datetime="2022-01-01">This text was deleted on New Year's Day.</del>

But here’s where things get interesting – these two attributes can actually work together as well! You can use both cite and datetime together to provide comprehensive details about a deletion:

<del cite="https://example.com/deletions" datetime="2022-01-01">This text was deleted on New Year's Day from https://example.com/deletions</del>

Pretty neat, right? Remember though – while these attributes add extra information, they’re not essential for the <del> tag to function. So if you don’t need ’em, it’s alright to leave ’em out.

One common mistake I’ve seen is neglecting to close the <del> tag. Always ensure you use </del> to indicate the end of a deletion. Without this closing tag, your text will continue being struck through until another block-level element is encountered.

So that’s the lowdown on the key attributes of the HTML <del> tag. By leveraging these attributes correctly, you’ll be able to provide clear and precise information about any deletions in your documents. And remember – practice makes perfect! Happy coding!

Practical Examples of Using the HTML <del> Tag

You’re probably wondering how to effectively utilize the HTML <del> tag. It’s a straightforward tool, but with a little finesse, it can add depth to your website content. Here are some practical examples that’ll make your understanding clearer.

Consider a blog post on your site that’s been updated with fresh information. You might want to strike through the outdated bits without actually removing them, making it clear to readers what has changed. That’s where our friend <del> comes in handy:

<p>The concert begins at <del>8pm</del> 7:30pm.</p>

In this example, “8pm” will appear struck through on your webpage, indicating that the original start time has been changed to “7:30pm”.

But let’s not stop there! The <del> tag is versatile and works well with other elements too. Ever thought about using it inside a list?

<ul>
   <li>Milk</li>
   <li><del>Eggs</del></li>
   <li>Bread</li>
</ul>

In this grocery list snippet, “Eggs” will show up as crossed out – maybe because you’ve already picked them up from the store!

Now remember, while <del> is useful for showing alterations or completed tasks, it’s crucial not to misuse it. Excessive strikethrough text can be distracting and hard on the eyes of your readers.

One common mistake is confusing <del> with <strike>. While both tags achieve similar visual effects (strikethrough), keep in mind that <strike> is deprecated and should not be used anymore.

Finally, don’t forget that you can combine the <del> element with datetime attribute in order to specify when exactly an element was deleted or altered:

<del datetime="2020-12-31T23:59:00Z">This text was deleted on New Year's Eve.</del>

The datetime attribute is a handy way to provide extra information to your readers and adds another layer of precision to your content. As always, remember that good web design is all about clear communication with your audience!

Common Mistakes and How to Avoid Them

HTML isn’t always a walk in the park, and even seasoned developers can run into some common pitfalls when using the <del> tag. Let’s delve into some of these mistakes and how you can sidestep them.

One error I’ve seen time and again is forgetting to close the <del> tag. HTML tags come in pairs, so for every opening <del>, there should be a corresponding </del>. Missing out on that closing tag can mess up your entire document structure.

<p>The price was <del>$100 now it's $80.</p>

In this example, “now it’s $80” shouldn’t be struck through but because we forgot to close our <del> tag, it is. Here’s how you’d correct that:

<p>The price was <del>$100</del> now it's $80.</p>

Another common mistake I’ve witnessed is misusing the <del> tag as a styling tool rather than for its semantic purpose. The <del> tag is intended to represent deleted or replaced text – not just any text you want to strike through. If you’re looking for visual effects only, CSS rules like text-decoration: line-through; would serve better.

Then there’s nesting errors – placing block-level elements such as paragraphs (<p>) or divisions (<div>) inside the <del> tags which are inline by nature. This disrupts the natural flow of your HTML document and may lead to unexpected results.

<del><p>This paragraph has been deleted.</p></del>

The correct way would be:

<p><del>This paragraph has been deleted.</del></p>

By being aware of these common mistakes with the HTML <del> tag, you’ll avoid major headaches down the line. Remember, always close your tags, use <del> for its intended semantic purpose and be mindful of nesting rules. With these tips in mind, you’ll be a master of the <del> tag in no time!

Conclusion: Mastering the Use of HTML <del> Tag

Having spent considerable time on this topic, I’m confident that you now grasp the utility and versatility of the HTML <del> tag. It’s such a nifty tool for web developers and content creators alike.

Let’s quickly recap what we’ve learned:

Now, let’s take one more look at an example:

<p>The price was <del>$100</del> $50.</p>

In this instance, the <del> tag indicates that the original price of $100 has been removed or replaced with the current price of $50.

Common mistakes to avoid when using the <del> tag include forgetting to close it properly and attempting to nest other block-level tags inside it. Here’s an incorrect usage:

<p>The price was <del>$100</p></del>.

Remember, proper structuring is crucial when using any HTML tags.

HTML coding is all about precision and attention to detail. As you continue your journey into web development, mastering tags like <del> will undoubtedly make your work stand out. Keep practicing and happy coding!

Cristian G. Guasch

Hey! I'm Cristian Gonzalez, I created HTML Easy to help you learn HTML easily and fast.

Related articles