Professional Documents
Culture Documents
HTML5
TABLE OF CONTENTS
Preface 2
Introduction 2
Basic HTML5 Syntax 2
Document Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Head Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Body Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
HTML5 Elements 5
Formatting Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Link Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Image Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Form Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Multimedia Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
HTML5 Attributes 10
Global Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Event Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Form Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Input Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Link Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Media Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
HTML5 Forms 15
Form Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
HTML5 Graphics 17
Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
SVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Audio Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Video Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
HTML5 APIs 18
Geolocation API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Canvas API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Best Practices 20
Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
SEO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
HTML5 Resources 22
References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
PREFACE
PREFACE Element Description
<html> This is the second
This HTML5 cheatsheet is a quick reference guide
for web developers who want to quickly look up element in an HTML5
HTML5 syntax, elements, attributes, APIs, and best document and wraps
practices. It provides a comprehensive overview of around all the other
HTML5, including its document structure, head and elements in the
body sections, text, formatting, link, image, table, document. It has two
form, multimedia, and graphics elements. It also main sections:a. The
covers HTML5 APIs, such as the Drag and Drop API, head section - This
as well as best practices for accessibility, SEO, and section contains meta
performance. In addition, this cheatsheet includes a data about the
list of helpful references, tools, frameworks, and document, such as the
libraries for web developers to use. title, keywords, and
description, as well as
links to external
INTRODUCTION
INTRODUCTION stylesheets and scripts.b.
The body section - This
HTML5 is the latest version of the HTML markup
section contains the
language used for creating web pages and
actual content of the
applications. With its new features and
document, such as text,
improvements, HTML5 offers developers more
images, and other
flexibility and ease of use when creating web
multimedia elements
content. This HTML5 cheatsheet is designed to
serve as a quick reference guide for web developers
who want to create HTML5 compliant pages or
<!DOCTYPE html>
applications. It includes sections on basic HTML5
syntax, document structure, elements, attributes,
<html>
APIs, best practices, and resources. Each section <head>
includes examples and explanations to help you <title>My HTML5 Document</title>
quickly understand the concepts and use them <meta charset="UTF-8">
effectively in your own web development projects. <meta name="description"
Whether you are a beginner or an experienced content="This is my HTML5 document">
developer, this cheatsheet will be a useful resource <meta name="keywords"
to keep at your fingertips. content="HTML5, document, web">
<link rel="stylesheet"
BASIC
BASICHTML5
HTML5SYNTAX
SYNTAX href="style.css">
</head>
DOCUMENT STRUCTURE <body>
<h1>Welcome to My HTML5
The document structure of an HTML5 document is
Document</h1>
the overall structure that defines how the
<p>This is the content of my
document is organized and displayed in a web
HTML5 document.
browser. The basic document structure of an
HTML5 document consists of the following <img src="image.jpg" alt="An
elements: image">
</body>
Element Description </html>
<!DOCTYPE>
</pre>
This is the first element
in an HTML5 document
and specifies the version In this example, we have the <!DOCTYPE> declaration
of HTML being used followed by the <html> element. Inside the <html>
element, we have the <head> element that contains
the title, meta data, and stylesheet. The <body> Element Description
element contains the actual content of the
<link> Defines a link to an
document, which includes a header, a paragraph of
external resource, such
text, and an image.
as a stylesheet or script.
Some common
HEAD SECTION attributes for the <link>
element include: rel:
The head section of an HTML5 document is used to
Specifies the
provide metadata about the document, including
relationship between
the document title, links to stylesheets, and scripts.
the current document
The head section is not displayed on the page itself,
and the linked resource.
but rather is used by the browser to provide
type: Specifies the MIME
information about the page.
type of the linked
The following elements can be included in the head resource. href: Specifies
section of an HTML5 document: the URL of the linked
resource.
• The link element with the rel attribute set to <ul> This element is used to
"stylesheet", which links to an external CSS create unordered lists. It
stylesheet file named "style.css". This file is typically used to
contains the styling information for the web display a list of items
page. that do not need to be in
any particular order
This is just a basic example, and there are many
<ol> This element is used to
other elements and techniques that can be used in
create ordered lists. It is
the head section of an HTML5 document,
typically used to display
depending on the specific needs of the web page.
a list of items that need
to be in a specific order
BODY SECTION
<li> This element is used to
The <body> section of an HTML5 document contains create individual list
the content that is displayed to the user. This is items within a list
where you will include text, images, videos, and <img> This element is used to
other elements that you want to appear on the
display images on the
page.
page. It is typically used
to display logos, photos,
Some of the most commonly used HTML5 elements
or other types of
for the body section include:
graphics
<a> This element is used to
create links to other
pages or resources. It is
typically used to create
navigation links or to
link to related content
Element Description
<img src="path/to/image.jpg" alt="A
<th> This element is used to
beautiful mountain landscape.">
create a header cell in
the table. It is typically
In this example, the img element is used to display used in the first row of
an image on the web page. The src attribute the table to label the
specifies the path to the image file, and the alt columns
attribute provides a text description of the image. If <thead><br><tbody><br>< These elements are used
the image cannot be displayed for any reason (e.g. if tfoot> to group table rows into
the file is missing or the network connection is
different sections. The
down), the text in the alt attribute will be displayed
<thead> element is used
instead.
to group the header
rows, the <tbody>
element is used to group
<img src="path/to/image.jpg" alt="A
the body rows, and the
beautiful mountain landscape."
<tfoot> element is used
width="500" height="300"
to group the footer rows
title="Click to view larger image">
<input type="submit"
value="Submit">
</form>
includes a text field for the user’s name, a radio audio element.
button group for the user’s gender, a checkbox for </audio>
the newsletter subscription, a dropdown menu for
the user’s favorite color, and a submit button to <video controls width="640"
submit the form data. height="360">
<source src="video/movie.mp4"
MULTIMEDIA ELEMENTS type="video/mp4">
Your browser does not support the
HTML5 provides several elements for embedding
video element.
multimedia content into web pages. These elements
include:
</video>
id attribute
Here’s an example of how to use these elements to
embed multimedia content into a web page:
This attribute is used to assign a unique identifier to
an HTML element. It is often used for styling or
scripting purposes. Here’s an example:
<audio controls>
<source src="audio/music.mp3"
type="audio/mpeg"> <h1>My Website</h1>
Your browser does not support the
style attribute
<script>
This attribute is used to apply inline styles to an
function myFunction() {
HTML element. Inline styles override any styles
alert("The page has finished
defined in an external CSS file or in a style element
loading!");
in the head section of the HTML document. Here’s
an example:
}
</script>
Sure, here are some examples of event attributes in This attribute is used to define a JavaScript function
HTML5: to be executed when an HTML form is submitted.
Here’s an example:
onclick
<body onload="myFunction()">
action
<!-- Rest of the HTML code goes
here --> This attribute is used to specify the URL of the
</body> server-side script that will process the form data
when the form is submitted. Here’s an example: used when submitting the form. The two most
common types are application/x-www-form-
urlencoded (default) and multipart/form-data. Here’s
<form action="process-form.php" an example:
method="post">
<!-- Form elements go here -->
<button <form action="process-form.php"
type="submit">Submit</button> method="post"
</form> enctype="multipart/form-data">
<!-- Form elements go here -->
<button
method type="submit">Submit</button>
</form>
This attribute is used to specify the HTTP method to
be used when submitting the form. The two most
common methods are GET and POST. Here’s an
INPUT ATTRIBUTES
example:
type
<form action="process-form.php"
This attribute is used to specify the type of input
method="post"> element. Some of the most common types are text,
<!-- Form elements go here --> password, checkbox, radio, submit, reset, and file.
<button Here are some examples:
type="submit">Submit</button>
</form>
<input type="text" name="username"
placeholder="Enter your username">
name <input type="password"
name="password" placeholder="Enter
This attribute is used to give the form a name,
your password">
which can be used to refer to the form in JavaScript
<input type="checkbox"
code. Here’s an example:
name="remember" id="remember"
value="true">
<form name="myForm" action="process- <label for="remember">Remember
form.php" method="post"> me</label>
<!-- Form elements go here --> <input type="radio" name="gender"
<button id="male" value="male">
type="submit">Submit</button> <label for="male">Male</label>
</form> <input type="radio" name="gender"
id="female" value="female">
<script> <label for="female">Female</label>
var myForm = <input type="submit" value="Submit">
document.forms["myForm"]; <input type="reset" value="Reset">
// JavaScript code that interacts <input type="file" name="photo">
with the form goes here
</script>
name
<a
<label href="https://www.example.com">Visit
for="username">Username:</label> Example.com</a>
<input type="text" name="username"
id="username">
target
rel
required
This attribute is used to specify the relationship
This attribute is used to specify that the input between the current document and the linked
element must be filled out before the form can be resource. The most common value is stylesheet to
submitted. Here’s an example: indicate that the linked resource is a CSS stylesheet
that should be applied to the current document.
Here’s an example:
<input type="text" name="username"
required>
<link rel="stylesheet"
href="styles.css">
placeholder
preload
<link rel="stylesheet"
href="styles.css" media="(min-width: This attribute is used to specify whether and how a
768px)"> video or audio file should be preloaded, or loaded
in the background, when the page loads. The
possible values are none, metadata, or auto. Here’s an
MEDIA ATTRIBUTES example:
autoplay
<audio src="audio.mp3"
This attribute is used to automatically start playing preload="auto"></audio>
a video or audio file when the page loads. Here’s an
example:
TABLE ATTRIBUTES
cellpadding
<video src="video.mp4" loop></video>
This attribute is used to specify the padding size of
the cells within a table, in pixels. Here’s an
poster example:
width
Password Input
This attribute is used to specify the width of a table,
The password input type is used for password
in pixels or percentage. Here’s an example:
fields. It hides the user input and can help prevent
unauthorized access.
<table width="80%">
<tr> <label
<th>Header 1</th> for="password">Password:</label>
<th>Header 2</th> <input type="password" id="password"
</tr> name="password" required>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<label for="agree-to-terms">Agree to
terms and conditions:</label> <label for="date-of-birth">Date of
<input type="checkbox" id="agree-to- Birth:</label>
terms" name="agree-to-terms" <input type="date" id="date-of-
required> birth" name="date-of-birth"
required>
Radio Button
Time
The radio button input type is used for a group of
radio buttons that the user can select only one of The time input type is used for accepting time
the options. values.
<label CANVAS
for="password">Password:</label> The <canvas> element allows for dynamic, scriptable
<input type="password" rendering of 2D shapes and bitmap images. Here’s
id="password" name="password" an example of how to create a canvas element in
minlength="8" required> HTML:
<label
<canvas id="myCanvas" width="200"
for="confirm_password">Confirm
height="200"></canvas>
Password:</label>
<input type="password"
id="confirm_password"
SVG
name="confirm_password"
minlength="8" required> The <svg> element allows for scalable vector
graphics. SVG is a markup language for describing
<input type="submit" two-dimensional graphics applications and images,
value="Submit"> and a set of related graphics script interfaces.
</form> Here’s an example of how to create an SVG element
in HTML:
#image {
const context = new AudioContext(); width: 100px;
const oscillator = height: 100px;
context.createOscillator(); background-color:
const gainNode = orange;
context.createGain(); margin: 10px;
}
oscillator.connect(gainNode); </style>
gainNode.connect(context.destination </head>
); <body>
Drop Here
oscillator.type = "sawtooth"; Drag Me
oscillator.frequency.value = 440;
<script>
gainNode.gain.value = 0.5; var dragImage =
document.getElementById("image");
oscillator.start(context.currentTime var dropzone =
); document.getElementById("dropzone");
oscillator.stop(context.currentTime
+ 1);
dragImage.addEventListener("dragstar
t", function(event) {
DRAG AND DROP API
event.dataTransfer.setData("text/pla
The Drag and Drop API in HTML5 allows web
developers to make web applications more user-
in", event.target.id);
friendly by enabling users to drag and drop });
elements on a web page. With this API, you can
allow users to drag elements such as images, files,
or text, and drop them into a designated area on the dropzone.addEventListener("dragover"
web page. , function(event) {
event.preventDefault();
The Drag and Drop API consists of a set of events,
methods, and properties that enable you to create a
dropzone.style.backgroundColor =
drag and drop functionality on your web page.
"yellow";
});
<!DOCTYPE html>
<html>
<head> dropzone.addEventListener("dragleave
<title>Drag and Drop ", function(event) {
Example</title>
<style> dropzone.style.backgroundColor = "";
#dropzone { });
width: 200px;
height: 200px;
border: 2px dashed dropzone.addEventListener("drop",
black; function(event) {
padding: 10px; event.preventDefault();
margin: 10px; var data =
} event.dataTransfer.getData("text/pla
This API allows a web application to run scripts in • Minimize the use of inline styles and scripts:
the background, freeing up the main thread for Using inline styles and scripts can make your
other tasks and improving performance. code harder to maintain and debug. Instead,
use external files for your styles and scripts.
easy to read, and make sure to use appropriate quality backlinks from reputable websites to
font sizes and spacing. help improve your site’s visibility and ranking.
• Provide captions and transcripts for • Monitor and analyze your traffic: Monitor
multimedia: Videos should include captions your website traffic and use analytics tools to
and audio files should have transcripts to gain insights into user behavior and optimize
ensure that deaf and hard-of-hearing users can your website accordingly.
access the content.
HTML5
HTML5RESOURCES
RESOURCES Reference Description
Here are some resources for learning more about HTML5 Doctor A site focused on
HTML5: teaching best practices
and use cases for
HTML5
Resource Description
CanIUse A website that allows
HTML5 Boilerplate A popular front-end
you to check the
template that provides a
compatibility of HTML5
starting point for
features across different
building modern, cross-
web browsers
browser compatible web
applications
These references can provide a wealth of
HTML5 UP A collection of free, information for developers looking to learn or
responsive HTML5 expand their knowledge of HTML5.
templates that can be
used as a starting point
TOOLS
for building websites
CSS-Tricks A website that provides There are many tools available for working with
tutorials, articles, and HTML5, including:
resources for working
with CSS, HTML, and Tool Description
JavaScript
Sublime Text Α popular text editor for
Stack Overflow A Q&A community for coding HTML5, with
programmers, including syntax highlighting and
those working with autocomplete features
HTML5. You can find
Atom Αnother popular text
answers to common
editor with similar
questions and ask your
features as Sublime Text
own
Adobe Dreamweaver Another popular text
editor with similar
REFERENCES features as Sublime Text
Some useful references for HTML5 are: Visual Studio Code Α lightweight code
editor with built-in
Reference Description support for HTML5, CSS,
and JavaScript
W3C HTML5 The official specification
Specification for HTML5 by the World Brackets Αn open-source HTML5
Wide Web Consortium editor with live preview
(W3C) and inline editing
features
Mozilla Developer An extensive resource
Network (MDN) for HTML5 CodePen Αn online code editor
documentation, and community for
tutorials, and examples sharing HTML5, CSS,
and JavaScript code
HTML5 Rocks A Google-run site with
snippets
articles, tutorials, and
examples on HTML5
and related technologies
JCG delivers over 1 million pages each month to more than 700K software
developers, architects and decision makers. JCG offers something for everyone,
including news, tutorials, cheat sheets, research guides, feature articles, source code
and more.
CHEATSHEET FEEDBACK
WELCOME
support@javacodegeeks.com
Copyright © 2014 Exelixis Media P.C. All rights reserved. No part of this publication may be SPONSORSHIP
reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, OPPORTUNITIES
mechanical, photocopying, or otherwise, without prior written permission of the publisher. sales@javacodegeeks.com