Hyper-Text Markup Language!
Save this text as a file:
<b>whatever</b>
give it a .html
extension and open your file in a web browser.
<i>...</i>
- make text italicized<u>...</u>
- underline some text<br>
- line break (aka "blank line")<img src="whatever.png">
- show an image!<a href="http://cool.com">cool</a>
- link!<h1>...</h1>
- headers (big text)
attributes are modifications/specifications that you can make to the tag.
<img src="cat.jpg" height="100" width="100">
all img
attributes: http://www.w3schools.com/tags/tag_img.asp
there are loads of tags.
full list: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
many are rarely used.
a few common ones are in this talk, but you can explore more tags with view source and inspect element
<div>...</div>
a box for text. it goes all the way across the screen.
<span>...</span>
a chunk of a single line.
useful if you want to style a small section of text within a div
<table>
<tr>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
<form method="post" action="/">
<p>
cats?
</p>
<input type="text" name="cats">
<p>
<input type="submit" value="submit!">
</p>
</form>
modify how your elements appear with styles
remember attributes?
some elements have attributes specific to them, but there are also "global" attributes that apply to every element.
- style
- class
- id
(all global attributes: http://www.w3schools.com/tags/ref_standardattributes.asp)
<h1 style="color:blue">...</h1>
<h1 style="color:blue;text-align:center">...</h1>
- Inline - using a style attribute in HTML elements
- Internal - using a
<style>
element in the HTML<head>
section - External - using one or more external CSS files
(the above is from http://www.w3schools.com/html/html_css.asp)
<html>
<head>
<style>
h1 {
display: block;
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
</style>
</head>
<body>
<h1>...</h1>
</body>
</html>
(from http://www.w3schools.com/tags/tag_hn.asp)
use an id when there will only be a single element
<html>
<head>
<style>
#msg {
font-weight: bold;
font-size: 72px;
color: magenta;
}
</style>
</head>
<body>
<div id="msg">wow!</div>
</body>
</html>
use a class when there could be many elements
<html><head>
<style>
.msg {
font-weight: bold;
font-size: 72px;
color: magenta;
}
</style>
</head>
<body>
<div class="cool">wow!</div>
<div class="cool">neat!</div>
<div class="cool">super!</div>
</body></html>
<link rel="stylesheet" href="style.css">
view the source on http://cyber.wizard.institute & explore the stylesheet.
You can create blocks of css rules that apply to more than just individual classes and ids with css selectors.
#page .row .title {
color: cyan;
}
will match <div class="title"></div>
in:
<div id="page">
<div class="row">
<div class="header">
<div class="title"></div>
<div class="date"></div>
<div class="author"></div>
</div>
</div>
</div>
We just used spaces between elements in #page .row .title
,
but we can do lots of other things with css:
p
- matches all elements with ap
tagdiv h2
- matches anyh2
tags that are below adiv
div > h2
- matches anyh2
tags that are directly below adiv
#pic1
- matches an element with the idpic1
.header
- matches an element with the classheader
h1 h2 h3
- matches allh1
h2
h3
'sdiv[foo="bar"]
- matches adiv
with an attributefoo
set tobar
div.cool#bar[baz="yay"]
- matches a div with the classcool
, the idbar
that has an attributebaz
set toyay
and more! http://www.w3.org/TR/CSS2/selector.html#pattern-matching
You can use css selectors directly from javascript:
<body>
<div id="neat">
<div class="msg">...</div>
</div>
<script>
document.querySelector('#neat .msg').textContent = 'cool!!!!'
</script>
</body>
You can host your html on neocities for free!