{"id":413,"date":"2024-01-02T15:21:00","date_gmt":"2024-01-02T15:21:00","guid":{"rendered":"https:\/\/techgurudehradun.in\/blog\/?p=413"},"modified":"2024-02-04T15:26:31","modified_gmt":"2024-02-04T15:26:31","slug":"html-style-guide","status":"publish","type":"post","link":"https:\/\/techgurudehradun.in\/blog\/?p=413","title":{"rendered":"HTML Style Guide"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Declaration of document type in HTML<\/h3>\n\n\n\n<p>It is crucial to specify the document type that the browser should display. This informs the browser about the type of document it needs to render and, consequently, utilize its resources. The appropriate document type for HTML5 is &#8211;<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!DOCTYPE Html><\/mark><\/p>\n\n\n\n<p>Not mentioning the document type is considered as a bad practice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Use of lowercase element names in HTML<\/h3>\n\n\n\n<p>While HTML permits the use of either lowercase or uppercase element names, we suggest opting for lowercase names. This choice enhances readability and makes the code easier to write.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;body><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;p>Welcome to Techguru&lt;\/p><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;\/body><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;BODY><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;P>Welcome to Techguru!&lt;\/P><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;\/BODY><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Close all elements in HTML<\/h3>\n\n\n\n<p>Although HTML does not require closing all elements, it is advisable to do so for better coding practices.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;body><br>&lt;p>Welcome to Techguru.&lt;\/p><br>&lt;\/body><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;body><br>&lt;p>Welcome to Techguru.<br>&lt;\/body><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Use Lowercase Attribute Names in HTML<\/h3>\n\n\n\n<p>Similar to elements, HTML does not offer a specific rule regarding the use of uppercase or lowercase names for attributes. Nevertheless, it is considered a good practice to employ lowercase letters for attribute names.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;a href=&#8221;https:\/\/tech-guru.training\/&#8221;>Welcome to Techguru&lt;\/a><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;a HREF=&#8221;https:\/\/tech-guru.training\/&#8221;>Welcome to Techguru&lt;\/a><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Quote Attribute Values in HTML<\/h3>\n\n\n\n<p>While developers often omit quoting attribute values, it is advisable to include quotes as it enhances code readability. Additionally, it is crucial to avoid using spaces in this context.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;table <strong>class<\/strong>= \u201cbordered\u201d><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;table <strong>class<\/strong>= bordered><\/mark><\/p>\n\n\n\n<p><strong>Does not work-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;table <strong>class<\/strong>= table striped><\/mark><\/p>\n\n\n\n<p>This does not work because of the spaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. Specification of alt, width, and height attributes of the image in HTML<\/h3>\n\n\n\n<p>Specifying the &#8216;alt&#8217; attribute is a commendable practice as it serves as an alternative text in case the browser cannot display the image. Likewise, utilizing the height and width attributes allocates space for the image before loading, preventing flickering.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;img src=&#8221;tree.jpg&#8221; alt=&#8221;Tree&#8221; height=&#8221;500px&#8221; width=&#8221;500px&#8221;><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;img src=&#8221;tree.jpg&#8221;><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. Spaces between equal signs in HTML<\/h3>\n\n\n\n<p>While it is permissible to include spaces within equal signs, it is strongly advised against due to its adverse impact on code readability.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;a href=&#8221;https:\/\/tech-guru.training\/&#8221;>Welcome to Techguru&lt;\/a><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;a href = &#8220;https:\/\/tech-guru.training\/&#8221;>Welcome to Techguru&lt;\/a><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. HTML Long Code Lines<\/h3>\n\n\n\n<p>It is recommended to avoid excessively long lines of code; instead, break them to prevent unnecessary horizontal scrolling.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. HTML Indentation and Blank lines<\/h3>\n\n\n\n<p>Avoid unnecessary blank lines and indentation in an HTML document. It&#8217;s better to use blank lines to separate code blocks, and limit indentation to two spaces rather than the tab key.<br><strong>Correct-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;body><br>&lt;h1>Techguru&lt;\/h1><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;h2>Mission&lt;\/h2><br>&lt;p>We strive to offer high-quality education at an affordable cost, assisting individuals in advancing their careers in the latest technologies. Our approach includes a unique teaching method that combines self-paced and instructor-led learning. We provide personalized guidance, lifelong access to courses, 24\/7 support, live projects, resume and interview preparation, and practical, job-ready learning. Our goal is to give learners real-time technical experience through our expert instructors. &lt;\/p><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;\/body><\/mark><\/p>\n\n\n\n<p><strong>Incorrect-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;body><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;h1>Techguru&lt;\/h1><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;h2>Mission&lt;\/h2><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;p>We strive to offer high-quality education at an affordable cost, assisting individuals in advancing their careers in the latest technologies. Our approach includes a unique teaching method that combines self-paced and instructor-led learning. We provide personalized guidance, lifelong access to courses, 24\/7 support, live projects, resume and interview preparation, and practical, job-ready learning. Our goal is to give learners real-time technical experience through our expert instructors. &lt;\/p><\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><br>&lt;\/body><\/mark><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. HTML &lt;title&gt; element<\/h3>\n\n\n\n<p>It&#8217;s crucial to include the &lt;title&gt; element in an HTML document for effective search engine optimization (SEO). Search engines use the web page&#8217;s name to determine its ranking in search results for relevant queries. Therefore, it&#8217;s important to name the web page accurately and choose a meaningful title.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;title>Techguru &#8211; Mastr&#8217;s of IT&lt;\/title>.<\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">11. HTML Omission of &lt;html&gt; and &lt;body&gt; tags<\/h3>\n\n\n\n<p>The HTML webpage can render successfully even without including the &lt;html&gt; and &lt;body&gt; elements. However, it&#8217;s advisable to include them. Omitting the &lt;body&gt; tag may lead to errors in older browsers, and excluding the &lt;head&gt; tag can cause issues with XML and DOM software.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;head><br>&lt;title>Page Title&lt;\/title><br>&lt;\/head><br>&lt;h1>Hi&lt;\/h1><br>&lt;p>Welcome&lt;\/p><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">12. HTML Omission of &lt;head&gt;<\/h3>\n\n\n\n<p>In HTML, you can skip using the &lt;head&gt; tag. The browser automatically includes all elements defined before the &lt;body&gt; tag in the default &lt;head&gt;.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!DOCTYPE html><br>&lt;html><br>&lt;title>Title&lt;\/title><br>&lt;body><br>&lt;h1>Hi&lt;\/h1><br>&lt;p>Welcome&lt;\/p><br>&lt;\/body><br>&lt;\/html><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. HTML Close empty tags<\/h3>\n\n\n\n<p>In HTML, closing empty tags is optional. However, when using XML or XHTML, the closing slash (\/) becomes necessary.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;meta charset= \u201cutf-8\u201d \/><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">14. HTML Lang attribute<\/h3>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Always specify the &#8220;lang&#8221; attribute to define the language of the web page for browsers and search engines.<\/mark><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!DOCTYPE html><br>&lt;html lang=&#8221;en-US&#8221;><br>&lt;head><br>&lt;title>Title&lt;\/title><br>&lt;\/head><br>&lt;body><br>&lt;h1>Hi&lt;\/h1><br>&lt;p>Welcome&lt;\/p><br>&lt;\/body><br>&lt;\/html><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. HTML Meta Data<\/h3>\n\n\n\n<p>The <code>&lt;meta&gt;<\/code> tag holds extra information about the document, including page description, keywords, author, character set, etc. Web browsers use this metadata to display content, and search engines rely on keywords for indexing.<\/p>\n\n\n\n<p><strong>Character Set-<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;meta charset=&#8221;UTF-8&#8243;><\/mark><\/p>\n\n\n\n<p>It is a good practice to define the meta charset at the earliest in an HTML document.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">16. Setting viewport in HTML<\/h3>\n\n\n\n<p>Use the &lt;meta&gt; tag of the head to create a viewport for a website.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!DOCTYPE html><br>&lt;html><br>&lt;head><br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;><br>&lt;\/head><br>&lt;body><br>&lt;h2>Viewport&lt;\/h2><br>&lt;p><strong>Try<\/strong> to run <strong>this<\/strong> code on different websites.&lt;\/p><br>&lt;\/body><br>&lt;\/html><\/mark><\/p>\n\n\n\n<p>The browser controls the scaling of the web-page, using the meta viewport. The width=device-width specifies that page\u2019s width will be equal to the device\u2019s width where the web page will be displayed.<\/p>\n\n\n\n<p>The initial-scale=1.0 is used to set the initial zoom level of the web-page when it is first loaded.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">17. HTML Comments<\/h3>\n\n\n\n<p><br>It&#8217;s recommended to use brief comments like:<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!\u2013following is a paragraph\u2192<br>Long comments like-<br>&lt;!\u2013<br>This is a long comment example.<br>This is a long comment example.<br>\u2013&gt;<\/mark><\/p>\n\n\n\n<p>Long comments become easily observable when indented with two spaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">18. HTML Style Sheets<\/h3>\n\n\n\n<p>To link stylesheets, use a straightforward linking syntax; the type attribute is not required.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;Techguru.css&#8221;><\/mark><\/p>\n\n\n\n<p>We should compress short CSS rules in a single line.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">p{font-family:Verdana; font-size:15px}<\/mark><\/p>\n\n\n\n<p>We should write long CSS rules over multiple lines.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">body {<br>background-color: black;<br>font-family: &#8220;Arial Black&#8221;;<br>font-size: 16em;<br>color: white;<br>}<\/mark><\/p>\n\n\n\n<p><strong>Note-<\/strong><\/p>\n\n\n\n<ul>\n<li>Use a space before the opening bracket.<\/li>\n\n\n\n<li>Use two spaces for indentation.<\/li>\n\n\n\n<li>Only Use quotes for the values if they contain spaces.<\/li>\n\n\n\n<li>Use a semicolon for each property-value pair.<\/li>\n\n\n\n<li>Place the closing bracket on the last line.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">19. JavaScript<\/h3>\n\n\n\n<p>The type attribute is not required when linking JavaScript files. Use a simple syntax.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;script src=&#8221;Techguru.js&#8221;><\/mark><\/p>\n\n\n\n<p><strong>Accessing HTML Elements<\/strong><br>Ensure proper use of id attributes to access HTML elements; otherwise, errors may occur.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;!DOCTYPE html><br>&lt;html><br>&lt;body><br>&lt;p id=&#8221;Demo&#8221;>Paragraph 1.&lt;\/p><br>&lt;p id=&#8221;demo&#8221;>Paragraph 2.&lt;\/p><br>&lt;script><br>\/\/ Paragraph 2 will be overwritten<br>document.getElementById(&#8220;demo&#8221;).innerHTML = &#8220;HELLO!&#8221;;<br>&lt;\/script><br>&lt;\/body><br>&lt;\/html><\/mark><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">20. HTML File names<\/h3>\n\n\n\n<p>Be mindful of the case sensitivity of web servers like Apache and Unix, as they may not recognize case-insensitive file names, such as delhi.jpg and Delhi.jpg. To avoid issues, it&#8217;s recommended to consistently use lowercase file names.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">21. HTML Extensions<\/h3>\n\n\n\n<p>Ensure that your HTML document carries the file extension .html or .htm, as they are interchangeable. Similarly, a CSS file should have the extension .css, and a JavaScript file should bear the extension .js.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">22. HTML Default Filenames<\/h3>\n\n\n\n<p>When a URL lacks a specified filename, the server automatically appends a default filename like index.html or default.html. Server configuration allows multiple default filenames, but it&#8217;s crucial to avoid using the same name for another file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Recap<\/h2>\n\n\n\n<p>In this article, we have explored the details of crafting an HTML document, highlighting best practices and proper syntax usage. Key aspects of the HTML Style Guide, including declaring document types, utilizing lang attributes, closing tags, employing lowercase names for attributes and elements, quoting values, and more, have been discussed. Additionally, we&#8217;ve delved into best practices for CSS and JavaScript, along with insights into setting viewports.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Declaration of document type in HTML It is crucial to specify the document type that the browser should display. This informs the browser about the type of document it needs to render and, consequently, utilize its resources. The appropriate document type for HTML5 is &#8211; &lt;!DOCTYPE Html> Not mentioning the document type is considered [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,24],"tags":[30,29],"_links":{"self":[{"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/413"}],"collection":[{"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=413"}],"version-history":[{"count":28,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techgurudehradun.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}