Always Use the Right HTML Elements
A lot of beginners make the common mistake of using the wrong HTML elements. They need to learn with time which element should be used where. We recommend you learn about all the HTML elements and use them correctly for a meaningful content structure. For example, instead of using <br> between two paragraphs, you can use CSS margin and/or padding properties. Learn when to use <em> and when to use <i> (both look the same), and learn when to use <b> and when to use <strong> (both look the same). It comes with practice and when you keep your eyes on good code written by other developers. Another good example is given below.
Note: To check the Difference between <i> and <em> tagstags, strong and bold tag in HTML
<!-- Wrong Practice -->
<span class="heading"><strong>Hello Geeks</strong></span>
<br><br>
This is Computer Science portal for geeks.
<br><br>
<!-- Right Practice -->
<h1>Hello Geeks</h1>
<p>This is Computer Science portal for geeks.</p>
Programming For Beginners: 10 Best HTML Coding Practices You Must Know
HTML is one of the easiest things to learn in programming. Most of the newbies and even kids step into programming picking up HTML. They learn they build some web pages but a lot of developers even experienced ones make some silly mistakes while writing the code for the front end. Making these silly mistakes not only annoys other developers (when they need to make some changes) but also hurts your main site and drives the end-user away. We are going to mention some common and best practices that you should follow to write clean and clear HTML code.
Following some common coding practices makes debugging easier and saves a lot of time. It also helps in search engine optimization as well.
Table of Content
- 1. Use Proper Document Structure With Doctype
- 2. Close the Tags
- 3. Write Tags in Lowercase
- 4. Add Image Attributes
- 5. Avoid Using Inline Styles
- 6. Use a Meaningful Title and Descriptive Meta Tags
- 7. Use Heading Elements Wisely
- 8. Always Use the Right HTML Elements
- 9. Proper Use of Indentation
- 10. Validate Your Code