HTML Cheetsheet
HTML Cheetsheet
HTML
<!DOCTYPE html>
Contains the contents of the <html>
<head>
HTML document. It should <!-- Metadata Here -->
contain all other tags </head>
<body> <body>
besides the <head> element
<!-- Document Body Here -->
to display the body of the
</body>
document. </html>
<!DOCTYPE html>
<html>
<head>
The root element of an <!-- Metadata Here -->
HTML document. All other </head>
<html> <body>
tags in the document should
<!-- Document Body Here -->
be contained in this tag.
</body>
</html>
<head>
Used to provide metadata <meta name="author" content="Christopher Moore">
<meta> </head>
about the HTML document.
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
This tag is used to denote a </tr>
<tr>
table. Should be used with <td>First row first cell</td>
<tr> (defines a table row) <td>First row second cell</td>
<table> and <td> (defines a table </tr>
cell within a row) tags. The <tr>
<td>Second row first cell</td>
<th> tag can also be used to <td>Second row second cell</td>
define the table header row. </tr>
</table>
</td>
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
Denotes the header cells <td>First row first cell</td>
<th> <td>First row second cell</td>
within a row within a table. </tr>
<tr>
<td>Second row first cell</td>
<td>Second row second cell</td>
</tr>
</table>
<!DOCTYPE html>
Defines the title of the <html>
HTML document displayed <head>
in the browser's title bar <title>Document Title</title>
</head>
<title> and tabs. It is required in all <body>
HTML documents. It should <!-- Document Body Here -->
be contained in the <head> </body>
tag. </html>
HTML
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
<td>First row first cell</td>
Denotes a row within a
<tr> <td>First row second cell</td>
table. </tr>
<tr>
<td>Second row first cell</td>
<td>Second row second cell</td>
</tr>
</table>
CSS
<!DOCTYPE html>
All HTML documents must <html>
<head>
start with this declaration. It <title>Document Title</title>
tells the browser what </head>
OCTYPE html> <body>
document type to expect.
Document body here
Note that this element has
</body>
no ending tag. </html>
Identifies a self-contained
piece of content that could <article
be distributed to other class="CSS-Style-Reference">
websites and platforms as a <h2>HTML</h2>
<p>HTML stands for Hypertext Markup Language.
<article> stand- alone unit. Similar to It is a standardized system for tagging text files to display specif
<div> tag in that it does not font, color, graphics, and hyperlinks on World Wide Web pages.</p>
render as anything special </article>
in the browser unless it is
styled with CSS.
<!DOCTYPE html>
Contains the contents of the <html>
<head>
HTML document. It should <title>Document Title</title>
contain all other tags </head>
<body> <body>
besides the <head> element
Document body here
to display the body of the </body>
document. </html>
<figure>
Used in conjunction with <img src="durham.jpg">
<figcaption> the <figure> tag to mark up <figcaption>Fig.1 - Durham, NC</figcaption>
an image. </figure>
<figure>
Used to mark up an image <img src="durham.jpg">
<figure> in conjunction with the <figcaption>Fig.1 - Durham, NC</figcaption>
<figcaption> tag. </figure>
Contains a footer of a
document and often <footer>
<p>Author: Christopher Moore</p>
contains information such
<footer> </footer>
as authoring, copyright info, <form action="/script.php">
contact info, sitemap, and
related documents.
<form action="/script.php">
<fieldset>
<legend>User:</legend>
<label for= "fname">First name:</label>
<input type="text" id="fname"
Creates an HTML form for name="fname"><br><br>
<form> <label for= "lname">Last name:</label>
user input. <input type="text" id="lname"
name="lname"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
<!DOCTYPE html>
<html>
<head>
Contains metadata and <title>Document Title</title>
should be placed after the </head>
<head> <body>
<html> tag and before the
Document body here
<body> tag. </body>
</html>
<header>
A container for introductory <h1>Header tag example</h1>
content such as heading <p>It works as a container for introductory content such as heading
<header> <p>Author: Christopher Moore</p>
elements, logo, or authoring
</header>
information.
<!DOCTYPE html>
<html>
<head>
The root element of an <title>Document Title</title>
HTML document. All other </head>
<html> <body>
tags in the document should
Document body here
be contained in this tag.
</body>
</html>
<head>
Used to provide metadata <meta name="author" content="Christopher Moore">
<meta> </head>
about the HTML document.
<nav>
<a href="home.html">Home</a>
Used to define a set of <a href="page1.html">Page 1</a>
<nav> <a href="page2.html">Page 2</a>
navigational elements.
</nav>
<script>
Used to embed Javascript in alert("Hello World");
<script> </script>
an HTML document.
<section>
Defines an important <h2>Introduction</h2>
section of a document. Can <p>This document provides some examples of how to
<section> use a variety of HTML elements</p>
be used within headers and
</section>
footers as well.
<head>
<style>
p {color:red}
</style>
Used to apply simple CSS to </head>
<style> <body>
an HTML document.
<p>This paragraph will be red because I've styled
the paragraph tag with CSS.</p>
</body>
<table>
<tr>
<th>Header cell 1</th>
This tag is used to denote a <th>Header cell 2</th></tr>
table. Should be used with <tr>
<tr> (defines a table row) <td>First row first cell</td>
<td>First row second cell</td>
<table> and <td> (defines a table </tr>
cell within a row) tags. The <tr>
<th> tag can also be used to <td>Second row first cell</td>
define the table header row. <td>Second row second cell</td>
</tr>
</table>
HTML
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
<td>First row first cell</td>
Denotes a cell within a row,
<td> <td>First row second cell</td>
within a table. </tr>
<tr>
<td>Second row first cell</td>
<td>Second row second cell</td>
</tr>
</table>
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
<td>First row first cell</td>
Denotes the header cells
<th> <td>First row second cell</td>
within a row within a table. </tr>
<tr>
<td>Second row first cell</td>
<td>Second row second cell</td>
</tr>
</table>
<!DOCTYPE html>
Defines the title of the <html>
HTML document displayed <head>
in the browser's title bar <title>Document Title</title>
</head>
<title> and tabs. It is required in all <body>
HTML documents. It should Document body here
be contained in the <head> </body>
tag. </html>
<table>
<tr>
<th>Header cell 1</th>
<th>Header cell 2</th>
</tr>
<tr>
<td>First row first cell</td>
Denotes a row within a
<tr> <td>First row second cell</td>
table. </tr>
<tr>
<td>Second row first cell</td>
<td>Second row second cell</td>
</tr>
</table>
JAVASCRIPT
Arrays Created by declaring the const Beatles = ["Ringo", "Paul", "George", "John"];
//Here Beatles[0] is "Ringo".
array elements in [ ]. An
array can be assigned to a
variable, usually using the
keyword const or var.
Arrays use zero based
HTML
indexing to access their
elements.
Constructor is new
Date([optional parameters]).
//create a new date from a string
If the constructor is var newDate = new Date("2021-1-17 13:15:30");
declared with no
Date() parameters, it returns //create a new date instance representing 17 Jan 2021 00:00:00
current local date and time. //note that the month number is zero-based
var newDate = new Date(2021, 0, 17);
New dates can be created by
passing parameters to new
Date function.
//Creates the element <p> and text "Hello World". Appends Hello Worl
<head>
Takes one tag name
<script>
parameter and creates an function addPara() {
element with that name. var newPara = document.createElement("p");
Can place the element var newText = document.createTextNode("Hello World!");
newPara.appendChild(newText);
document.createElement() elsewhere on the page using document.body.appendChild(newPara);
functions like }
insertBefore(), </script>
appendChild(), </head>
<body onload="addPara()">
replaceChild(). </body>
//Creates the element <p> and text "Hello World". Appends Hello Worl
<head>
<script>
function addPara() {
var newPara = document.createElement("p");
Takes a string as input text var newText = document.createTextNode("Hello World!");
newPara.appendChild(newText);
document.createTextNode() and returns a text node document.body.appendChild(newPara);
with the input text. }
</script>
</head>
<body onload="addPara()">
</body>
Returns the value of the //Removes the CSS style color blue
specified attribute. Takes <div id="div1" style="color: blue"></div>
<script>
element.getAttribute() one parameter: the attribute var div1 = document.getelementById("div1").getAttribute("style");
name whose value is to be </script>
returned.
//Changes the content of the div to "Hello
World!"
<div id="div1">
<p>Hello</p>
A property of the Element <p>Hello</p>
class that returns or alters </div>
element.innerHTML()
contents of an HTML
<script>
element as a text string.
document.getElementById("div1").innerHTML = "<p>Hello
World!</p>";
</script>
HTML
Navigator Objects The navigator object is part //Retrieves the name of the browser
var browsername = navigator.appName;
of the window object class
in the DOM that represents
the client Internet browser,
also called the user agent.
There is no standard for this
object so what it returns
HTML
differs from browser to
browser.
A DOM event that starts a //Executes myFunction after MyHTMLPage has been loaded
onload() method when a page is document.getElementById("MyHTMLPage").onload = function () {myFuncti
loaded.
//Creates a new node and replaces the second element in "thisList" w
After creating an element, let secondBullet = document.createTextNode("blue");
replaceChild() this function replaces a var myList = document.getElementById("thisList").childNodes[1];
child node with a new node. myList.replaceChild(secondBullet, myList.childNodes[1]);