Freemote Logo

Coding Wiki

Most Common Coding Questions

Find answers to popular programming questions and level up your coding skills

Do you need slash in self-closing html tags

Learn about the use of self-closing HTML tags and when to include a slash.

Answer:

Self-closing HTML tags, also known as void elements, do not require a slash before the closing tag. For example, <img> and <br> are self-closing tags.

html
<img src="image.jpg" />

However, if you're using a tag that can be used as both a void element and an opening tag (e.g., <input>), it's generally considered better practice to include the slash. This helps avoid potential issues with parsing.

html
<input type="text" />
Tags:
html
☾☾☾
+++++++++
Level Up Your Coding Skills

JavaScript Cheat Sheet

Remember the essentials of 5 different languages, it's free.