AirBNB is a classic example of a booking site, and learning how to build a site like this allow us to perform the following functions:
- Display items with images and descriptions
- Accept booking details (e.g. name, email, date of arrival, number of pax, etc.)
- Store booking details
This is what we are going to cover in this tutorial. The technical part that we are going to cover includes:
- Using HTML to define the structure of our website
- Populate the content, descriptions and images using tags
- Send booking details to our email
- Design responsive layout using Bootstrap, so that our sites can be viewed nicely on different devices (desktop, mobile phones, tablets, and even TVs)
We first need to create a HTML file to describe the basic layout of our web page. In most cases, this file is named index.html.
Bootstrap is a responsive CSS framework. What it does is to help users to get a consistent look across different devices of different resolutions. Since it is a framework, we will have to follow a specific set of syntax to set it up. We will need the following component to start using bootstrap:
- container – the most basic layout element required in Bootstrap to use the grid system.
- row – wrapper for columns.
- col – the actual column where we place content.
You may also visit here for full documentation of Bootstrap. Let’s configure our Bootstrap page, and also use put in some text.
The HTML tags used here are:
- div – division tag. To create content block.
- p – paragraph tag. To create text passage.
- h1, h3 – header tags. Usually used for title and subheadings. It ranges from h1 to h6. Where h1 being most important and h6 being the least.
First of all we want to put down the content of all the tours. In bootstrap, we store our content in columns, and each column belongs to a particular row.
The HTML tag used here is:
- img – image tag. To display pictures specified in the src attribute.
The completed code should look like below:
Next we are going to include accommodation details to our page. Let’s use the similar structure as tour details.
Now head to your browser and open the index.html. You should see your page like the screenshot below. Well done! Let’s write some CSS styles to beautify our booking site.
Styling with CSS
CSS stands for Cascading Style Sheet. Think of CSS like a cosmetic or make up for your website. HTML defines the structure and the content, and we will use CSS to change the font size, color and the layout. As CSS determines the look and feel, it should always be loaded as early as possible. It is always defined in the head section of our HTML page, so that it is loaded before the content.
Let’s write some CSS styles to achieve the following:
- Configure the images to occupy 100% of the column (so that it will not overflow when we resize the screen)
- Remove the extra spacing around title, location and price.
- Change the text of location to UPPERCASE
- Set the font size of location to 12px, title to 16px, price to 14px
- Set the font weight of location and title to bold, price to 400
- Set the text color of location to brown
It looks like a lot of tasks isn’t it? But it can be easily translated to CSS styles, and give our site a good face lift.
You If you look closely at AirBNB site, or most of the modern looking websites, they actually don’t use black as the primary text color. Instead they use dark grey as their primary color. That’s what the body style is for, we set it to a RGB color of (72,72,72). Now, enter the entire style tag in your head tag. The tour item at your website should look like the screenshot below now. Note that the location has changed to all UPPERCASE automatically. The font size and font weight are also applied correctly.
Our site looks good now and we have populated the necessary details for tour and accommodation. Next we are going to include a booking form to capture our guest details and allow them to select the tour and accommodation that they want. First of all, let’s build a booking form like the one below.
The booking form contains four input elements that collect name, email, date and number of days. There is a submit button that will send us an email with the booking details.
To create the form, we will use the
form element. A form can then consists of
input elements such as textbox, checkbox, radio buttons, buttons for us to capture user inputs.
Also, when we use a form, we will set the method property POST in most cases, and the action URL determines where should the form data be sent to for processing. In this example, we will send the form data to
https://email@example.com. This is a handy external service that will forward your form data to the email address stated (in this case, it will be sent to firstname.lastname@example.org)
The placeholder property displays a hint when there is no content for the input. The different type of the input field will determine how it will be rendered (e.g. a date picker for the date field, a spinner for a number field).
The hidden field is a special field. It can’t be seen by users, but it can be used to store data that will be sent together with the field. Since it is hidden and not be seen by users, it is mainly used to submit information that is not entered by the visitor. In our case, we use it to store the tour item that is selected.
The last bit that we need to handle here is what should happen when an item is clicked. Let’s see what should happen where a button is clicked:
- Deselect the item that was previously selected (if any)
- Select the current item
- Extract the value of the selected item and store it in the hidden input, so that it will be submitted together with other input elements.
Ok, all of the things are wired properly. If you have been followed everything step-by-step correctly. You should see the page like this when you refresh your browser (with index.html opened).
We hope that you learn a lot and manage to pick up the knowledge required to book a functioning booking site. You may visit http://theleadio.github.io/airbnb_demo_2018 for the full demo and https://github.com/theleadio/airbnb_demo_2018 to download the source code. Do let us know in the comments if you have any questions and queries!