Web 101: Intermediate Elements of a Web Page
Here we go again! Here’s a quick recap with a basic introduction to HTML, the most basic required elements of HTML, and the common elements of HTML. As discussed in the first couple posts about web development basics, websites are built on HTML, and HTML revolves around tags. Tags are not displayed on your browser; they’re used in the code to label pieces of content.
Now we’re ready to dive into the intermediate elements of a webpage. These elements start to make your page look like you’ve put some real effort into it. Some of the most common intermediate elements include:
Forms are used to collect information from a user. These can range from a simple newsletter signup that only requires an email address, to a very complex, multi-step survey. There are three basic elements that make a form work: a form tag, an input tag for data, and an input tag for submitting the form. You can also include label tags, but they are not mandatory.
Here’s an example of a simple newsletter signup form:
The form tag <form></form> surrounds all the inner label and input tags, and usually has two attributes: action and method.
- Action: This attribute is used to designate the “Form Handler” file, which is typically in a server-side code language. In this example, we are using PHP. The server-side code language will differ depending on the type of server your webpage will live on. The code in the “Form Handler” file does things like input validation, error handling, saving data to a database, and more.
- Method: This attribute specifies the HTTP method used when submitting a form. There are only two options: get or post. Explaining the differences can get pretty advanced (and could very well take up an entire blog post), but the most basic overview is:
- “Get” is used when data needs to be requested from a website’s database.
- “Post” is used when data needs to be saved to a website’s database.
The input tag is a self-closing tag (meaning it does not require a closing tag) that requires at least two attributes: name and type.
- Name: This attribute is used the name the input. This name should always be unique. In other words, make sure not to name another input in the same form by the same name. Doing so can cause problems when the form is submitted to the form handler.
- Type: This attribute is used to denote the type of input requested. There are many “types” to choose from, but we’ll stick with the basics for now:
- Text creates the single line text input.
- Textarea creates a text box input.
Ex: <input name=”input_name” type=”input_type”>
The submit input is a special case that requires the attributes: type and value.
Ex: <input type=”submit” value=”Submit”>
You can learn more about all the different input types here.
How you set up a working form usually depends on what server-side coding language you’re dealing with, so here is where we stop … for now.
The iframe tag is a very interesting type of HTML tag. These tags are most commonly used to embed other websites into your site. It may be very confusing until you see an example in action, but first, let’s look at a code example:
Even though the iframe element has opening and closing tags, you do not need to add any content inside the tags because everything is set with the attributes. The bare minimum attribute you need is the “src” attribute, which tells the iframe what url to pull content from. Check out two common examples below:
Here is an example of a YouTube embed:
Here is an example of a Google Map embed:
That’s about as much as we can get into regarding elements of a webpage without really sending your head spinning, so this is it, friends. Melz, signing off.