32
loading...
This website collects cookies to deliver better user experience
This article is also available in the following languages: Portuguese.
💡 If you are not familiar with the HTML syntax, you should check my article “CSS and HTML Explained for Absolute Beginners: Part 1” before continue on this current one, as some markup language knowledge may be necessary.
“Search Engine Optimization”, by Gerd Altmann from Pixabay
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="/favicon.png">
[...]
<title>My simple web page</title>
<meta name="description" content="In order to fully understand SEO, we have to start by the basics, learning its fundamentals.">
[...]
</head>
💡 Some browsers provide better information about the metadata gathered from the current webpage. If you're using Mozilla Firefox, you can open the Site Information panel by pressing Ctrl + I
on your PC, or by following this guide. The opened window should look like this:
StackOverflow's homepage — yes, they do have a homepage! — seen in Firefox's Site Information panel.
LTR
) direction;viewport
definitions for rendering the current webpage;icon
, the title
, and a description
about this page.head
element.head
element is meant to provide some information about the page, such as rendering definitions, links, style-sheets, and scripts. Most of this metadata are not human-readable, and will not be displayed on the page, but will be only interpreted by the web server, and by the client's web browser.head
element to provide better results, which means that we can insert meta tags to improve the visibility of our webpages and applications, like by following the HTML's formatting syntax.The html
element represents the root of an HTML document.
The HTML DOM nodes structure. Image from W3Schools.
p
elements (for the paragraphs), or images and its caption — like this one:<figure>
<img src="/media/cc0-images/elephant-660-480.jpg" alt="Elephant at sunset">
<figcaption>An elephant at sunset</figcaption>
</figure>
alt
attribute on the example above: it can be used by screen readers, for blind and visually impaired people, so they can know what this image is about; but also for SEO purposes, as we can describe for the search engine what this figure is about, and how it's related to near text.💡 The best practice is to place the most important figure near the top of the webpage, like a banner image, and the other images near its context, such as the relevant text or section's heading.
head
element. For example:<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0">
<meta name="generator" content="WordPress 5.6">
<title>The document metadata</title>
<meta name="author" content="John Doe">
<meta name="description" content="This article explains the HTML metadata">
<meta name="keywords" content="html,metadata,rfc">
<link rel="alternate" type="application/atom+xml" href="blog-posts.xml">
<link rel="canonical" href="http://www.example.com/html/">
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
</head>
💡 According to the HTML5 Standard, void elements, such as link
and meta
tags are self-closing, as they don't have any content. It means you can end them by just typing >
, instead of />
. Other void elements include: area
, base
, br
, col
, embed
, hr
, img
, input
, param
, source
, track
, and wbr
.
meta
tag is used for defining metadata about the HTML file, and can modify the way web browsers render the document.name
attribute, such as author
, description
, generator
, and keywords
. Most of them are self-descriptive, and automatically informed by modern frameworks already.UTF-8
, the default charset
—; (ii) to specify the device's size (also to enable the responsive behavior); and (iii) to identify the software that generated the webpage.<meta name="author" content="John Doe">
<meta name="description" content="This article explains the HTML metadata">
<meta name="keywords" content="html,metadata,rfc">
💡 Most of the search engines use this metadata to provide a short description of the webpage on their results, so using a good mix of keyword phrases can lead us to make better results. But be careful: numerous unnecessary keywords should be avoided, as they may harm your position.
rating
metadata, so it won't be included in the search results for users that are not allowed, don't want, or don't expect to find these, when using search filters, like Google's SafeSearch. It can be done by including one of the following meta tags:<meta name="rating" content="adult" />
<meta name="rating" content="RTA-5042-1996-1400-1577-RTA" />
title
tag defined in the HTML file.link
element.<link>
tag, tells the web browser to get this file, and use its content in the current web page. For example:<link rel="icon" href="favicon.png">
<link href="default-stylesheet.css" rel="stylesheet">
<link href="https://example.com/css/print.css" rel="stylesheet" media="print">
<link href="mobile.css" rel="stylesheet" media="screen and (max-width: 576px)">
default-stylesheet.css
. Notice that files can also be located outside the current page's directory, as we are reaching the https://example.com/css/print.css
file from a different web server.media
attribute specifies that this resource should only be used by the web browser when the media condition is true. So, in our example, if we are trying to print this web page, our web browser will render the page according to the style-sheets located in that file.@media print {
.banner > p {
background-color: #ffffff;
color: #000000;
}
}
💡 HTML respects the order of the information provided, so we can set a new CSS file to override the previous one: by adding an external resource link element after the default-stylesheet.css
line, in our example.
mobile.css
file: if we are opening this page on a device which screen is 576px or less, the browser will render the webpage according to its file.💡 There are some common breakpoints, based on the general screen size ranges, such as: 576px (small devices), 768px (medium devices), 992px (large devices), and 1200px (extra-large devices).
“Responsive Web Design”, by Clovis Cheminot from Pixabay
rel
attribute as well, that can set a relationship between some linked resources and our current webpage.rel
attribute must express tokens that are semantically valid for both machines and humans. In our example, we already used three of them:<link rel="alternate" type="application/atom+xml" href="blog-posts.xml">
<link rel="canonical" href="http://www.example.com/html/">
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
alternate
value describes other representations of the current document, such as a syndication feed, or an alternative format and language, intended for other media types. In our example, we are demonstrating that there is an Atom Feed for our blog-posts as an alternate representation.canonical
value should be use if there is a single page that can be accessed on multiple URLs, or different pages containing the same content. It may occur when there are duplicate versions of the same page, such as example.com/html/
and example.com/?p=html
, so all the other URLs with similar content will be considered duplicate URLs and crawled less often.💡 Many developers usually post the same content on multiple blogging platform, or information channels, to engage a larger audience. This technique is known as “crossposting”, and should be used along with the canonical
URL, so search engines can prioritize the one that is the most representative from a set of the duplicate pages.
license
value indicates the licensing information for the current element or webpage. It can be used on the <a>
, <area>
, <form>
, or <link>
HTML elements, and so provided a hyperlink with the rules and declarations, like this:
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
💡 The synonym copyright
is incorrect and must be avoided, although recognized by many web browsers and search engines.
link
tag, however, can't be used for loading scripts: instead, we can use the script
tag.script
tag is used for embed executable code, and is typically used to include JavaScript code. It can also contain data, such as JSON (JavaScript Object Notation), that can be processed in our web page or application.link
tags, script
elements can refer to JavaScript code located in another web server or directory, like this example:<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
integrity
and the crossorigin
attributes when adding this request to an external web server. It is a good practice, in order to create more secure applications that the web browser check the response.integrity
attribute prevents web browser to load content that doesn't match with the expected response from the web server. It contains a hash of a resource as its value, that ensures that the file was received unmodified and delivered without unexpected manipulation.crossorigin
attribute defines how the element handles cross-origin requests, by adding an Origin
field into the HTTP Request to a server from a different origin. It provides support for Cross-Origin Resource Sharing (CORS) mechanism, and can be set to either anonymous
(default), or use-credentials
values: the first one creates CORS requests with the credentials flag set to same-origin
; the second one, with the credentials flag set to include
.💡 HTML's link
and script
tags can implement the integrity
and crossorigin
in order to provide better security, by allowing proper verification of the received data and its source.
head
or in the body
of our HTML file, so the web browser would request for the file before or after the page's content is fully loaded. Also, it can be loaded in parallel with the rendering of the webpage's elements, asynchronously, or synchronously.script
element right after all the elements of the webpage are defined: in general, this way you can ensure the user will not be presented to a blank page until all the scripts are loaded, what can take some time depending on the users' network.💡 For the purposes of this article, we won't cover the pros and cons of inserting the script
element on the head
or the body
element yet, nor doing it synchronously or asynchronously, as these topics require an article for themselves. In fact, you can follow this series as we will learn it in another time.
link
and script
tags inside the head
or body
element shouldn't matter, as search engine crawlers usually won't read scripts or style-sheets, rather than our HTML content. On the other hand, their placement may impact users' experience, and the order of their declarations matter to other scripts that use them as dependencies.meta
, link
, and script
tags, and how to use it correctly in order to achieve better search engine results.body
element, and how it can be implemented for better SEO results. Make sure to follow it. 🏆