Introduction to web technologies
HTML + CSS + Javascript
Created by: Javi Agenjo
Edited: Jeff Borland
Goals
Introduction to web technologies:
Technologies
HTML
HTML means Hyper Text Markup Language.
The HTML allow us to construct the visible part of a website.
HTML is NOT a programming language, it’s a markup language, which means its purpose is to give structure to the content of the website.
It is a series of nested tags (it is a subset of XML) that contain all the website information (like texts, images and videos). Here is an example of tags:
<title>This is a title</title>
The HTML defines the page structure. A website can have several HTMLs to different pages.
<html>
<head>
</head>
<body>
<div>
<p>Hi</p>
</div>
</body>
</html>
HTML: syntax example
<div id="main">
<!-- this is a comment -->
This is text without a tag.
<button class="mini">press me</button>
<img src="me.png" />
</div>
HTML: syntax example
<div id="main">
<!-- this is a comment -->
This is text without a tag.
<button class="mini">press me</button>
<img src="me.png" />
</div>
Tag name
attributes
comment
text tag
self-closing tag
HTML: main tags
Although there are lots of tags in the HTML specification, 99% of the webs use a subset of HTML tags with less that 10 tags, the most important are:
HTML good use
It is good to have all the information properly wrapped in tags that give it some semantics.
We also can extend the code semantics by adding extra attributes to the tags:
<div id="profile-picture" class="mini-image">...</div>
Technologies
CSS
Allows to specify how to present (render) the document info stored in the HTML.
Allows to controls all the aspects of the visualization and some other features:�
CSS example
someTag {
color: blue; /*a comment */
margin: 10px;
font: 14px Tahoma;
}
This will change someTag to look blue with font Tahoma with 14px, and leaving a margin of 10px around.
CSS fields
Here is a list of the most common CSS fields and an example:
Layout
CSS also deals with how the entire page looks and how you arrange pieces on the screen.
Technologies
Javascript
A regular programming language, easy to start, hard to master.
Allows to give some interactivity to the elements on the web.
You can change the content of the HTML or the CSS applied to an element.
You can even send or retrieve information from the internet to update the content of the web without reloading the page.
Javascript: insert code
There is three ways to execute javascript code in a website:
<script> /* some code */ </script>
<script src="file.js" />
<button onclick="javascript: /*code*/">press me</button>
Javascript: Syntax
Very similar to C++ or Java but much simpler.
var my_number = 10; //this is a comment�var my_string = "hello";�var my_array = [10,20,"name",true];�var my_object = { name: "javi", city: "Barcelona" };��function say( str )�{� for(var i = 0; i < 10; ++i)� console.log(" say: " + str );�}
Javascript API
Javascript comes with a rich API to do many things like:
And the API keeps growing with every new update of the standard.
Check the WEB API reference to know more
Example of a website
HTML in index.html
<link href="style.css" rel="stylesheet"/>
<h1>Welcome</h1>
<p>
<button>Click me</button>
</p>
<script src=”code.js”/>
CSS in style.css
h1 { color: #333; }
button {
border: 2px solid #AAA;
background-color: #555;
}
Javascript in code.js
//fetch the button from the DOM
var button = document.querySelector(“button”);
//attach and event when the user clicks it
button.addEventListener(“click”, myfunction);
//create the function that will be called when the button is pressed
function myfunction()
{
//this shows a popup window
alert(“button clicked!”);
}