These are the HTML-specific coding styles. Anything mentions here overrides/adds to the "In General" guides. The only 1 principle when coding HTML is that:
https
).<!-- Recommended -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Not recommended: omits the protocol -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Not recommended: uses HTTP -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<table>
) requires a minimum 4 indentation levels in order to make itself complete. Hence, 8 spaces tab is not suitable.<!-- Recommended -->
<img src="google.png" alt="Google">
<!-- Not recommended -->
<A HREF="/">Home</A>
Recommended:
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test</title>
<article>This is only a test.</article>
Not recommended:
<html>
<meta charset="utf-8">
<title>Test</title>
<article>This is only a test.</article>
<div>
tag.Recommended:
<!-- Recommended -->
<a href="recommendations/">All recommendations</a>
Not recommended:
<!-- Not recommended -->
<div onclick="goToRecommendations();">All recommendations</div>
alt
meta to your media tags like <img>
.alt
meta presents something as part of the design when the media failed to render.Recommended:
<!-- Recommended -->
<img src="spreadsheet.png" alt="Spreadsheet screenshot.">
Not recommended:
<!-- Not recommended -->
<img src="spreadsheet.png">
Recommended:
<!DOCTYPE html>
<title>My first CSS-only redesign</title>
<link rel="stylesheet" href="default.css">
<h1>My first CSS-only redesign</h1>
<p>I’ve read about this on a few sites but today I’m actually
doing it: separating concerns and avoiding anything in the HTML of
my website that is presentational.
<p>It’s awesome!
Not recommended:
<!DOCTYPE html>
<title>HTML sucks</title>
<link rel="stylesheet" href="base.css" media="screen">
<link rel="stylesheet" href="grid.css" media="screen">
<link rel="stylesheet" href="print.css" media="print">
<h1 style="font-size: 1em;">HTML sucks</h1>
<p>I’ve read about this on a few sites but now I’m sure:
<u>HTML is stupid!!1</u>
<center>I can’t believe there’s no way to control the styling of
my website without doing everything all over again!</center>
Recommended:
<!-- Recommended -->
The currency symbol for the Euro is “€”.
Not recommended:
<!-- Not recommended -->
The currency symbol for the Euro is “&eur;”.
Not Omitting Version:
<!-- Not recommended -->
<!DOCTYPE html>
<html>
<head>
<title>Spending money, spending bytes</title>
</head>
<body>
<p>Sic.</p>
</body>
</html>
Omitting Version:
<!-- Recommended -->
<!DOCTYPE html>
<title>Saving money, saving bytes</title>
<p>Qed.
Recommended:
<link rel="stylesheet" href="https://www.google.com/css/maia.css">
<script src="https://www.google.com/js/gweb/analytics/autotrack.js"></script>
Not recommended:
<!-- Recommended -->
<link rel="stylesheet" href="https://www.google.com/css/maia.css" type="text/css">
<script src="https://www.google.com/js/gweb/analytics/autotrack.js" type="text/javascript"></script>
link
and script
tags are configured default to interpret CSS and JavaScript files respectively. Make use of them.Recommended:
<blockquote>
<p><em>Space</em>, the final frontier.</p>
</blockquote>
<ul>
<li>Moe</li>
<li>Larry</li>
<li>Curly</li>
</ul>
<table>
<thead>
<tr>
<th scope="col">Income</th>
<th scope="col">Taxes</th>
<tbody>
<tr>
<td>$ 5.00</td>
<td>$ 4.50</td>
</table>
link
and script
tags are configured default to interpret CSS and JavaScript files respectively. Make use of them.Recommended:
<md-progress-circular
md-mode="indeterminate"
class="md-accent"
ng-show="ctrl.loading"
md-diameter="35">
</md-progress-circular>
<md-progress-circular md-mode="indeterminate"
class="md-accent"
ng-show="ctrl.loading"
md-diameter="35">
</md-progress-circular>
That's all for HTML coding style.