Posted on 2018/02/12 at 1:47 am
I love web technologies because they provide a quick return on interest (ROI) and for the beginner gives immediate feedback in terms of accomplishment and sense of progress. There are many frameworks that one can use for a web based project but knowing the base elements these frameworks are comprised from is still important. Here is a reference list/cheat sheet of some of the most common HTML tags, CSS, and JavaScript one will likely use. This is great for Web Devs, Web Admins, coders, programmers, and the like.
<tag>Stuff in tag...</tag> (open tag)content(/end tag) <!--Some tags end like this--> <tag/>
<img src="https://www.itdominator.com/wp-content/uploads/2017/07/wp-cli.jpg" alt="If image doesn't render, this text will show instead." />
<!--To an external page...--> <a href="http://www.google.com" target="_blank">Google</a> <!--This will jump to the content that is wrapped with another anchor tag on the same page.--> <a href="#colors">Colors</a> <a name="colors"> <p>Colors are cool. The primary colors are red, green, and blue.</p> </a>
| Firstname | Lastname |
|---|---|
| Tom | Gar |
| Lois | Griffin |
| Firstname | Lastname |
|---|---|
| Peter | Griffin |
| Lois | Matt |
| Object | Preview | HTML 5 code |
|---|---|---|
| Label | <label>Texte</label> | |
| Button | <input type="button" name="name" value="Bouton"> | |
| Image button | <input type="image" src="image/bimage.jpg"> | |
| Text field | <input type="text" name="text" value="empty"> | |
| Password | <input type="password" name="monpass" value="12345"> | |
| Date | <input type="date" name="date" value="<?php echo $today?>"> | |
| Date and time | <input type="datetime" name="time" value="<?php echo $now?>"> | |
| Time | <time>2013-06-27</time> | |
| Number | <input type="number" name="num" value="12345"> | |
| Color | <input type="color" name="color" value=""> | |
| Search input | <input type="search" name="" list="datalist" value=""> | |
| Data | Dix | <data value="10">Ten</data> |
| Check box | <input type="checkbox" name="checkbox1" value="checkbox"> | |
| Radio group |
|
<label>Choice 1 <input type="radio" name="radio1" value="radio1"> </label> <label>Choice 2 <input type="radio" name="radio1" value="radio2"> </label> |
| Textarea | <textarea name="textarea">content</textarea> | |
| Range | <input type="range" min="-100" max="100" value="0" step="2" name="power" list="powers"> <datalist id="powers"> <option value="0"> <option value="-30"> <option value="30"> <option value="+50"> </datalist> | |
| Data list | To be used with input | <datalist id="identifier"> <option value="1"> <option value="2"> <option value="3"> </datalist> |
| Select | <select name="select"> <option>Alpha</option> <option>Beta</option> <option>Delta</option> </select> | |
| Select list | <select name="select2" size="3"> <option>Alpha</option> <option>Beta</option> <option>Delta</option> </select> | |
| Menu | <menu type="context"> <li>New</li> <li>Open</li> <li>Save</li> </menu> | |
| Toolbar | <menu type="toolbar"> <li><button type="button" onclick="fnew()">New</button></li> <li><button type="button" onclick="fopen()">Open</button></li> <li><button type="button" onclick="fsave()">Save</button></li> </menu> | |
| Combo box | <input type="text" list="comboid"> <datalist id="comboid"> <option value="0"> <option value="-30"> <option value="30"> <option value="+50"> </datalist> | |
| File upload | <input type="file" name="file"> | |
| Image & caption |
![]() |
<figure> <img src="image/image.gif"> <figcaption>Caption</figcaption> </figure> |
| Fieldset | <fieldset> <legend>Title </legend> <p>Content</p> </fieldset> | |
| Output | <output onforminput="value = 2 + 2"></output> | |
| Meter |
|
<meter min=0 max=24 value=12>12 units</meter> |
| Progress | <progress id="prog" max=100> | |
| Summary |
Overview
|
<details> <summary> Presentation </summary> <dl> <dt>term</dt> <dd>definition</dd> ... </dl> </details> |
| Submit button | <input type="submit" name="submit" value="Submit"> | |
| Clear/Reset button | <input type="reset" name="clear" value="Clear"> |
| Result | Description | Entity Name | Entity Number |
|---|---|---|---|
| non-breaking space | |   | |
| < | less than | < | < |
| > | greater than | > | > |
| & | ampersand | & | & |
| " | double quotation mark | " | " |
| ' | single quotation mark (apostrophe) | ' | ' |
| ¢ | cent | ¢ | ¢ |
| £ | pound | £ | £ |
| ¥ | yen | ¥ | ¥ |
| € | euro | € | € |
| © | copyright | © | © |
| ® | registered trademark | ® | ® |
<!DOCTYPE html> <!--Tells a browser its an html page--> <html lang="en"> <head> <meta charset="utf-8"> <!--Encoding model--> <title>Title seen on its tab</title> <link rel="stylesheet" href="/css/master.css"> <!-- Attach CSS through a path --> </head> <body> <!-- content goes here... --> <script src="resources/scripts/script.js" charset="utf-8"></script> <!-- Attach Javascript File through path --> </body> </html>
| Selector | Example | Example description |
|---|---|---|
| .class | .intro | Selects all elements with class="intro" |
| #id | #firstname | Selects the element with id="firstname" |
| * | * | Selects all elements |
| element | p | Selects all <p> elements |
| element,element | div, p | Selects all <div> elements and all <p> elements |
| element element | div p | Selects all <p> elements inside <div> elements |
| element>element | div > p | Selects all <p> elements where the parent is a <div> element |
| element+element | div + p | Selects all <p> elements that are placed immediately after <div> elements |
| element1~element2 | p ~ ul | Selects every <ul> element that are preceded by a <p> element |
| [attribute] | [target] | Selects all elements with a target attribute |
| [attribute=value] | [target=_blank] | Selects all elements with target="_blank" |
| [attribute~=value] | [title~=flower] | Selects all elements with a title attribute containing the word "flower" |
| [attribute|=value] | [lang|=en] | Selects all elements with a lang attribute value starting with "en" |
| [attribute^=value] | a[href^="https"] | Selects every <a> element whose href attribute value begins with "https" |
| [attribute$=value] | a[href$=".pdf"] | Selects every <a> element whose href attribute value ends with ".pdf" |
| [attribute*=value] | a[href*="w3schools"] | Selects every <a> element whose href attribute value contains the substring "w3schools" |
| :active | a:active | Selects the active link |
| ::after | p::after | Insert something after the content of each <p> element |
| ::before | p::before | Insert something before the content of each <p> element |
| :checked | input:checked | Selects every checked <input> element |
| :disabled | input:disabled | Selects every disabled <input> element |
| :empty | p:empty | Selects every <p> element that has no children (including text nodes) |
| :enabled | input:enabled | Selects every enabled <input> element |
| :first-child | p:first-child | Selects every <p> element that is the first child of its parent |
| ::first-letter | p::first-letter | Selects the first letter of every <p> element |
| ::first-line | p::first-line | Selects the first line of every <p> element |
| ype.asp">:first-of-type | p:first-of-type | Selects every <p> element that is the first <p> element of its parent |
| :focus | input:focus | Selects the input element which has focus |
| :hover | a:hover | Selects links on mouse over |
| sp">:in-range | input:in-range | Selects input elements with a value within a specified range |
| :invalid | input:invalid | Selects all input elements with an invalid value |
| :lang(language) | p:lang(it) | Selects every <p> element with a lang attribute equal to "it" (Italian) |
| sp">:last-child | p:last-child | Selects every <p> element that is the last child of its parent |
| ype.asp">:last-of-type | p:last-of-type | Selects every <p> element that is the last <p> element of its parent |
| :link | a:link | Selects all unvisited links |
| :not(selector) | :not(p) | Selects every element that is not a <p> element |
| sp">:nth-child(n) | p:nth-child(2) | Selects every <p> element that is the second child of its parent |
| hild.asp">:nth-last-child(n) | p:nth-last-child(2) | Selects every <p> element that is the second child of its parent, counting from the last child |
| f-type.asp">:nth-last-of-type(n) | p:nth-last-of-type(2) | Selects every <p> element that is the second <p> element of its parent, counting from the last child |
| ype.asp">:nth-of-type(n) | p:nth-of-type(2) | Selects every <p> element that is the second <p> element of its parent |
| ype.asp">:only-of-type | p:only-of-type | Selects every <p> element that is the only <p> element of its parent |
| sp">:only-child | p:only-child | Selects every <p> element that is the only child of its parent |
| :optional | input:optional | Selects input elements with no "required" attribute |
| ange.asp">:out-of-range | input:out-of-range | Selects input elements with a value outside a specified range |
| sp">:read-only | input:read-only | Selects input elements with the "readonly" attribute specified |
| sp">:read-write | input:read-write | Selects input elements with the "readonly" attribute NOT specified |
| :required | input:required | Selects input elements with the "required" attribute specified |
| :root | :root | Selects the document's root element |
| ::selection | ::selection | Selects the portion of an element that is selected by a user |
| :target | #news:target | Selects the current active #news element (clicked on a URL containing that anchor name) |
| :valid | input:valid | Selects all input elements with a valid value |
| :visited | a:visited | Selects all visited links |
<!-- The IDs are arbitrary. --> <div id="left-container"> <!-- Content --> </> <div id="middle-container"> <!-- Content --> </> <div id="right-container"> <!-- Content --> </>
// Get HTML element(s) with specified id.
var x = document.getElementById('id');
// Get HTML elements with specified class.
var x = document.getElementsByClassName('className');
// Get HTML elements with specified tag.
var x = document.getElementsByTagName('tagName');
// Get HTML elements tht matches a specified CSS selector
// This example returns a list of all
elements with class="icon".
var x = document.querySelectorAll("img.icon");
function sum(a, b) {
return a + b; // The function returns the sum of a and b
}
var sumVal = sum(2,4);
alert(sumVal); // Will pop-up saying 6
// Standard loop
for (var i=0; i<array.length; i++) {
array[i].innerHTML;
}
// For In Loop
for (var tag in elements) {
// Do stuff while there are tags to work on
}
// While Loop
while (condition) {
// Do stuff while condition is met
}
// Do While
do {
// One at least one and keep doing stuff while condition is met
}
while (condition);
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
alert(day);
// This will generate a pop-up window with the "Hello, World!" text.
alert("Hello, World!");
// This will log to the console the "Hello, World!" text.
To access the console in Firefox, do Ctrl+Shift+J
console.log("Hello, World!");
// This attaches a click event to the entire DOM.
// We can then check which IDs, Classes, etc were clicked to then do other things.
document.addEventListener("click", (e) => {
if(e.target.id == "alert2")
alert("You clicked an element with the ID of alert2");
});
// This attaches to a specific element with the ID of cars and
// when clicked alerts us to the innerHTML text.
<p id="cars">Hello, World!</p>
document.getElementById('cars').addEventListener("click", (e) => {
alert("The content is: " + e.target.innerHTML);
});
// This attaches it in a different manner.
document.getElementById('cars').onclick = function(){
// do stuff
}
// You can add it though a tag as well.
<div onclick="myFunction()"> I am clickable! </div>
Here is a list of some common HTML event attributes:
| Event | Description |
|---|---|
| onchange | An HTML element has been changed |
| onclick | The user clicks an HTML element |
| onmouseover | The user moves the mouse over an HTML element |
| onmouseout | The user moves the mouse away from an HTML element |
| onkeydown | The user pushes a keyboard key |
| onkeyup | The user releases a keyboard key |
| onload | The browser has finished loading the page |
// An empty array
var cars = [];
// Has nodes/objects
var cars = ["Toyota", "Sab", "Mazda"];
// Add to array
cars.push("Nesan');
// Remove from end of array
cars.pop();
<div>
<p id="cars" >
Cars are cool.
</p>
But boats are even more cool.
</div>
var x = document.getElementById('cars').parentElement;
alert(x.innerHTML); // This will present an alert box with "But boats are even more cool."
// This will remove the element we accessed from the div
var childElm = document.getElementById('cars');
var parentElm = childElm.parentElement;
parentElm.removeChild(childElm);
function saveAsCookie() {
var uName = document.getElementsByName("userName")[0].value;
var eml = document.getElementsByName("email")[0].value;
// should set expires date: Ex -> expires=(UTC date).
// Use secure; in argument to make sure it only transports across HTTPS or secure connections
document.cookie = "username=" + uName +"; path=" + document.URL;
document.cookie = "email=" + eml + "; path=" + document.URL;
}
function displayCookies() {
var cookiesField = document.getElementById("cookieField");
var cookies = document.cookie.split(";"); // Set as an array to traverse....
for (var i=0; i<cookies.length; i++) {
cookiesField.innerHTML += cookies[i] + "<br/>";
}
}
function clerCookies() {
var expireDate = "Thu, 01 Jan 1970 00:00:00 UTC";
document.cookie = "username=; expires=" + expireDate;
document.cookie = "email=; expires= " + expireDate;
}
<form>
<input type="text" title="User Name" name="userName" placeholder="User Name" value=""/>
<input type="text" title="Email" name="email" placeholder="Email" value=""/>
<input type="button" name="submit" onclick="saveAsCookie()" value="loginSubmit">
</form>
<button type="button" name="button" onclick="displayCookies()">Get Cookie</button>
<button type="button" name="button" onclick="clerCookies()">Clear Cookie</button>
<div id="cookieField"></div>
function loadDoc() {
var xhttp = new XMLHttpRequest(); // Create the xhttp object
xhttp.onreadystatechange = function() { // This is actually run after open and send are done
if (this.readyState == 4 && this.status == 200) { // Confirm we have a successful connection
// Receive the response info. For PHP it is echo that sends it. Then set into demo div
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true); // post or get, path to XML page or php script, set async
xhttp.send(); // Start the process
}
<button type="button" name="button" onclick="loadDoc()">Load XML</button>
<div id="demo">
// Find sub string
var str = "Hello world, welcome to the universe.";
var n = str.includes("world");
// Find sub string at offset
var str = "Hello world, welcome to the universe.";
var n = str.includes("world", 12);
// Replace string
var str = "Windows!";
var res = str.replace("Windows", "Linux"); // old value, new value
// Replace all case sensitive
var str = "Mr Blue has a blue house and a blue car";
var res = str.replace(/blue/g, "red");
// Replace all case-insensitive
var str = "Mr Blue has a blue house and a blue car";
var res = str.replace(/blue/gi, "red");
// String split
var str = "How are you doing today?";
var arry = str.split(" "); // Split by spaces
// To Upper
var x = "Linux";
x.toUpperCase();
// To Lower
var x = "LINUX";
x.toLowerCase();