HTML General Ideas It is a markup language for creating webpages HTML - Hyper Text Markup Language Basically useless without CSS It must end in .html Doesn’t need a server Index.html is the root of the server Exclusive to local until a domain name is bought General Page Layout: <!DOCTYPE html> <html> <head> <title>Page title</title> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html> Layout Elements → <header> - Defines a header for a document or a section → <nav> - Defines a container for navigation links → <section> - Defines a section in a document → <article> - Defines an independent self-contained article → <aside> - Defines content aside from the content (like a sidebar) → <footer> - Defines a footer for a document or a section → <details> - Defines additional details → <summary> - Defines a heading for the <details> element Headings <meta <meta <meta <meta <meta charset="UTF-8"> name="description" content="Free Web tutorials"> name="keywords" content="HTML,CSS,XML,JavaScript"> name="author" content="John Doe"> http-equiv="refresh" content="30"> Viewports: → The viewport allows for the web page scale to vary based upon the size of the screen. For example, a display for a mobile device as opposed to a computer. <meta name="viewport" content="width=device-width, initialscale=1.0"> → <base></base> - specifies the URL and base target for all relative URLs in a page. <base href="https://www.w3schools.com/images/" target="_blank"> Elements → All elements can have attributes → Provide information about an element → Placed within the start tag → Key/value pairs (id = “someId”) Comments: <!-- This is a comment --> Images → <img></img> - defines an image → src – specifies the source for the image → alt – alternative text (in case the image doesn’t display) → width – defines image width → height – defines image height <img src="html5.gif" alt="HTML5Icon" style="width:128px;hei ght:128px;"> → float - decides where to put the image → <map></map> - allows for a certain area of an image to carry a link <img src="workplace.jpg" alt="Workplace" usemap="#workmap"> <map name="workmap"> <area shape="rect" coords="34,44,270,350" alt="Computer"h ref="computer.htm"> Change the picture for different window lengths: <picture> <source media="(min-width: 650px)" srcset="img_pink_flowers.jpg"> <source media="(min-width: 465px)" srcset="img_white_flower.jpg"> <img src="img_orange_flowers.jpg" alt="Flowers" style="wi dth:auto;"> </picture> Image As A Link: <a href="default.asp"> <img src="smiley.gif" alt="HTML tutorial"style="width:42px;height:42px;border:0;"> </a> Lists → Unordered(<ul></ul>) or Ordered(<ol></ol>). Followed by <li> tags. → type – defines the type of list marker → start – specifies what number the list should start counting at <ul> <li>Coffee</li> <li>Tea <ul> <!-- Nested List --> <li>Black tea</li> <li>Green tea</li> </ul> </li> <li>Milk</li> </ul> Description Lists: → <dl></dl> - defines a description list → <dt></dt> - defines the term → <dd></dd> - describes each term <dl> <dt>Coffee</dt> <dd>- black hot drink</dd> <dt>Milk</dt> <dd>- white cold drink</dd> </dl> Horizontal List: <!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333333; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 16px; text-decoration: none; } li a:hover { background-color: #111111; } </style> </head> <body> <ul> <li><a <li><a <li><a <li><a </ul> href="#home">Home</a></li> href="#news">News</a></li> href="#contact">Contact</a></li> href="#about">About</a></li> </body> </html> Horizontal Rule → <hr> - defines a thematic break in an HTML page. Used to separate content. Preformatted Text → Definition: <pre></pre> allows for preserved format as it is typed in HTML <pre> My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnie lies over the ocean. Oh, bring back my Bonnie to me. </pre> Tables → <table> - defines the table → <tr> - defines each row → <th> - defines the header (bold and centered by default) → <td> - defines table data/cell → <caption> - adds a caption → <colgroup> - Specifies a group of one or more columns in a table for formatting → <col> - Specifies column properties for each column within a <colgroup> element → <thead> - Groups the header content in a table → <tbody> - Groups the body content in a table → <tfoot> - Groups the footer content in a table → colspan – make a cell span more than one column → rowspan – make a cell span more than one row <table style="width:100%"> <caption>Monthly savings</caption> <tr> <th>Name</th> <th colspan="2">Telephone</th> </tr> <tr> <th rowspan="2">Telephone:</th> <td>55577854</td> </tr> <tr> <td>Bill Gates</td> <td>55577854</td> <td>55577855</td> </tr> </table> Text Formatting → <b> - Bold text → <strong> - Important text → <i> - Italic text → <em> - Emphasized text → <mark> - Marked text → <small> - Small text → <del> - Deleted text → <ins> - Inserted text → <sub> - Subscript text → <sup> - Superscript text → <q> - Quoted text → <blockquote> - Sectioned quote from a source → <abbr> - Abbreviated text <p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p> → <address> - defines contact information → <cite> - Inline citation for a work → <bdo> - defines bi-directional override <bdo dir="rtl">This text will be written from right to left</bdo> Responsive Test Size: → This style allows for text to resize the text as the window changes by using a “viewport width” unit, or “vw” <h1 style="font-size:10vw">Hello World</h1> Attributes → alt - specifies an alternative text to be used when an image cannot be displayed. → lang - declares the language for the document. Declared within the html tag (<html lang="en-US">). → title - added to elements so the value of the title attribute will be displayed as a tooltip when moused over. <a href="https://www.w3schools.com/html/" title="Go to W3Schools HTML section">Visit our HTML Tutorial</a> → id - Specifies a unique id for an element. target: specifies where to open the linked document → _blank - Opens the linked document in a new window or tab → _self - Opens the linked document in the same window/tab as it was clicked (this is default) → _parent - Opens the linked document in the parent frame → _top - Opens the linked document in the full body of the window → framename - Opens the linked document in a named frame <a href="https://www.w3schools.com/" target="_blank">Visi t W3Schools!</a> Bookmarks → Create id: <h2 id="C4">Chapter 4</h2> → Add link(same page): <a href="#C4">Jump to Chapter 4</a> → Add link(different page): <a href="#C4">Jump to Chapter 4</a> Inline and Block Level Elements Inline Elements: → Do not start on a new line → Take only the necessary width Block Elements: → Start on a new line → Take full width available Iframe → <iframe></iframe> - Used to display a website within a website → attributes - src, height, width <iframe src="demo_iframe.htm" style="height:200px;width:300px;"></if rame> → By default, an iframe has a border around it. To remove it, use the attribute style=”border:none;” → An iframe can be used as the target frame for a link. → The target attribute of the link must refer to the name attribute of the iframe: <iframe src="demo_iframe.htm" name="iframe_a"></iframe> <p><a href="https://www.w3schools.com" target="iframe_a">W3School s.com</a></p> Computer Code Elements → <code></code> - defines a fragment of computer code (use <pre> to maintain whitespace and line-breaks → <kbd></kbd> - represents user key input → <samp></samp> - represents output from a program or computing system <code> x = 5; y = 6; z = x + y; </code> → <var></var> - defines a variable Entities → Some characters are reserved in HTML. → If you use the less than (<) or greater than (>) signs in your text, the browser might mix them with tags. → Character entities are used to display reserved characters in HTML &entity_name; OR &#entity_number; Non-breaking Space: → A non-breaking space is a space that will not break into a new line. → Two words separated by a non-breaking space will stick together (not break into a new line). This is handy when breaking the words might be disruptive. Examples: § 10 10 km/h 10 PM XHTML → The same as HTML, but stricter and more compatible with other browsers or devices. HTML Forms → <form></form> - used to collect user input Inputs: → <input type=”text”> - defines a one-line text input field <form> First name:<br> <input type="text" name="firstname"><br> Last name:<br> <input type="text" name="lastname"> </form> → <input type=”radio”> - defines a radio button <form> <input type="radio" name="gender" value="male" checked>Male<br> <input type="radio" name="gender" value="female"> Female<br> <input type="radio" name="gender" value="other"> Other </form> → <input type=”submit”> - defines a submit button (for submitting the form) <form action="/action_page.php"> First name:<br> <input type="text" name="firstname" value="Mickey"><br> Last name:<br> <input type="text" name="lastname" value="Mouse"><br><br> <input type="submit" value="Submit"> </form> → action - attribute that defines the action to be preformed when the form is submitted. → method - attribute that specifies the HTTP method (GET or POST)to be used when submitting the form data. <form action="/action_page.php" method="get"> → GET – use to make form data visible in the page address field → POST – use if form data contains sensitive or personal information → name - each input field must have a name attribute to be submitted <form action="/action_page.php"> First name:<br> <input type="text" value="Mickey"><br> Last name:<br> <input type="text" name="lastname" value="Mouse"><br><br> <input type="submit" value="Submit"> </form> → <fieldset> - used to group related data in a form → <legend> - defines a caption for the <fieldset> element <form action="/action_page.php"> <fieldset> <legend>Personal information:</legend> First name:<br> <input type="text" name="firstname" value="Mickey"><br> Last name:<br> <input type="text" name="lastname" value="Mouse"><br><br> <input type="submit" value="Submit"> </fieldset> </form> → <select> - element defines a drop-down list → <option> - element defines an option that can be selected → size - attribute to specify the number of visible values → multiple - attribute to allow the user to select more than one value <select name="cars" size="4" multiple> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> → <textarea> - defines a multiple line text box o rows – defines the number of visible line o cols – defines the width of the text box → <button> - defines a clickable button <button type="button" onclick="alert('Hello World!')">Click Me!</button> → <datalist> - specifies a list of pre-defined options for an input The list attribute of the input element must refer to the id attribute of the datalist element. → <output> - represents the result of a calculation INPUT TYPES: → <input type="button"> - defines a simple button → <input type="checkbox"> - defines a checkbox for checking one or more options → <input type="color"> - used for input fields that should contain a color (a color picker will likely pop up) → <input type="date"> - used for input fields that contain a date (a date picker will likely pop up). Use the attributes “min” and “max” to restrict the dates <form> Enter a date before 1980-01-01: <input type="date" name="bday" max="1979-12-31"><br> Enter a date after 2000-01-01: <input type="date" name="bday" min="2000-01-02"><br> </form> → <input type="datetime-local"> - specifies a date and time input field → <input type="email"> - used for input fields that should contain an email adress → <input type="file"> - defines a file-select field and a “Browse” button for file uploads → <input type="hidden"> → <input type="image"> → <input type="month"> - allows the user to select a month and year → <input type="number"> - defines a numeric input field. Restrictions can be added <form> Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5"> </form> → <input type="password"> - defines a password field → <input type="radio"> - defines a radio button for only one option → <input type="range"> - defines a control for entering a number whose exact value is not important. The default range is 0 to 100 but this can be changed by the min, max, and step attributes → <input type="reset"> - defines a reset button that will reset all form values to their default values → <input type="search"> - used for search fields → <input type="submit"> - defines a button for submitting form data to a form-handler → <input type="tel"> - used for inputs that should contain a phone number → <input type="text"> → <input type="time"> - allows the user to select a time → <input type="url"> - allows for inputs that should contain a URL address → <input type="week"> - allows the user to select a week and year Input Restrictions: → disabled - Specifies that an input field should be disabled → max - Specifies the maximum value for an input field → maxlength - Specifies the maximum number of character for an input field → min - Specifies the minimum value for an input field → pattern - Specifies a regular expression to check the input value against → readonly - Specifies that an input field is read only (cannot be changed) → required - Specifies that an input field is required (must be filled out) → size - Specifies the width (in characters) of an input field → step - Specifies the legal number intervals for an input field → value - Specifies the default value for an input field Input Attributes: → value - defines the initial value for an input field → readonly - specifies that the input filed is read only and cannot be changed → disabled - specifies that the input field is disabled (cannot be clicked or changed) → size - defines the amount of characters for the input field → maxlength - defines that max allowed length for the input field → autocomplete - allows for text to be predicted as it is typed <form action="/action_page.php" autocomplete="on"> First name:<input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> Email: <input type="email" name="email" autocomplete="off"><br> <input type="submit"> </form> → nonvalidate - specifies that the form should not be validated upon submission → autofocus - specifies that the input field should automatically get focus when the page loads → formaction - used to override the initial action page for the form (used with submit and image types) → formenctype - specifies how the form data should be encoded when submitted (only for forms with POST method) <form action="/action_page_binary.asp" method="post"> First name: <input type="text" name="fname"><br> <input type="submit" value="Submit"> <input type="submit" formenctype="multipart/form-data" value="Submit as Multipart/form-data"> </form> → formmethod - used to override the initial method of the form (POST or GET) → formnonvalidate - used to override the validate status of the form → formtarget - used to override the initial target for the form → list - refers to a datalist element that contains pre-defined options for an input element → placeholder - specifies a hint that describes the expected value of an input field → required - specifies that the input field must be filled out before the form is submitted