Easy professional HTML and CSS layout tutorial

Layout a web article with html and css, so that it fits perfectly

In this tutorial, I am going to teach you how to layout an article or post, using HTML and CSS from scratch. We are going to start from the "raw" text, and we are going to format and design it so that it is irresistibly attractive to read. We'll add a couple of illustrations, and reuse some parts to make standout sentences.

At first, the idea of this tutorial was to offer some tips and advice to ensure that an article or post looks professional, using the editor of our CMS: WordPress or whatever, because we can do this either using a classic visual editor of the so-called WYSWYG, like a modern block editor, Gutenberg, Elementor and all these "builder composers" that are available on the market.

But I finally decided to do it pure and simple code. The reason for this decision is that if you follow the tutorial, you will learn basics of Html and css basics that will be of great help to you even if in your daily life (it is also in mine) you work with a visual editor. Because you will understand much better how the structure, presentation and behavior of what you insert so easily in your article works.

As a developer, I deliver websites and blogs to clients whose content will be inserted later by them. Obviously, the use of CMS with its themes and templates does not imply that the person who uses them necessarily has technical knowledge; Anyone can write a post on a blog or social network adding photos, etc.

But I can show you that the result can be spectacular if you dedicate a little care to what you do, much more than taking the Word article, pasting the title and content, putting a photo and marking four bold letters (if you get there). to the latter).

Start laying out the article

Let's fuck this article about artificial intelligence which I have outlined using precisely one of them. We start, as you see, from the pure and simple text with just a few line breaks.

Add HTML markup

If you have previewed the text in your browser (you can drag the txt file into the browser to do this), you may have noticed that the accents don't look right. They're fine, don't worry, but at the moment, they don't look good. For example, download the file, and open it in your Notepad (quick mode, right click on the file and "open with..."), Textedit, in Visual Studio Code, or the text editor of your choice.

Once the file is open, before doing anything, you are going to save it as "el-boom-de-las-ia.html". Or with whatever name you want, but make sure you save it as an html file type.

Now, let&#039;s start adding our HTML markups. The first one you must add is, at the beginning of the entire file: <html> and at the end of everything, </html>. This is the root opening and closing tag of a valid html document (if it does not have these tags, it is no longer valid). The HTML language consists of opening markups (example <marca> and closing marks </marca>. You mark things as <desde aquí>my content</hasta_aqui>, to define what each block is.

Remember that HTML is a representative language: It is used to mark and structure data, but it is NOT a programming language. You cannot program anything in HTML.

Next, we start by adding labels to the text. The first line is the main title of the article, so we are going to mark it as the main heading (heading 1) with the H1 tag:

The boom of AI in consumer technologies

We are going to label the rest of the paragraphs, as they are, with the P tag for "paragraph", like this:

  

The artificial intelligence boom refers to an ongoing period of rapid and unprecedented development in the field of artificial intelligence, with the generative AI race being a key component of this boom, which began in earnest with the founding of OpenAI. in 2016 or 2017¹. AI is already the main driver of emerging technologies such as big data, robotics and IoT, not to mention generative AI, with tools such as ChatGPT and AI art generators gaining widespread attention, and will continue to act as a technological innovator in the foreseeable future.

So, everyone the same with <p> and </p>. When we write text in HTML, although in our editor we can simply press enter and make as many line breaks as we want, when we preview the file in the browser, these line breaks will be ignored. In HTML, the line break occurs either after the closing of a block (The closing of a paragraph with </p> , for example) or we can also create forced line breaks, &quot;break a line&quot; with the tag <br> (abbreviation of break, line-break).

The label <br> it writes itself. That is, it does not have to be written as <br></br>. BR is a “self-sealing” label. There are other labels that go alone without closure such as IMG, INPUT, but you will learn this little by little.

If we wanted to force one or more line breaks in the middle of a paragraph, it would be as shown below:

  

The AI boom refers to an ongoing period of rapid and unprecedented development in the field of artificial intelligence, with the generative AI race being a key component of this boom, which began in earnest with the founding of OpenAI. in 2016 or 2017¹.

<!-- Estas dos etiquetas
fuerzan 2 saltos de línea -->
AI is already the main driver of emerging technologies such as big data, robotics and IoT, not to mention generative AI, with tools such as ChatGPT and AI art generators gaining widespread attention, and will continue to act as a technological innovator in the foreseeable future.

Do you see that clear text that is preceded by « » ? That's a brand too. A comment mark. It is used to put what you want in your code, without it being interpreted. In this way, we add our notes to the code, without that text appearing on the screen.

Depending on the context and morphology of our writing, we may need a simple line break, or close another paragraph. There is a visual difference: A line break skips the same space occupied by any additional line. On the other hand, a paragraph creates (and must create) a space with respect to the previous paragraph.

When we have finished determining and marking all our paragraphs, we will mark one of them as a secondary title (a subtitle that will act as a separator for the second part of the article). In an HTML page there should never be more than one H1 tag, which is why we use H2 like this, on the line you see:

As for the long term, it is difficult to predict exactly what this technology will have in store for us. However, it is clear that AI is constantly changing our world and will continue to do so in the future.

What could the future of humanity hold for us living with AI.

There are many hypotheses and ideas about what it will be like to live with AIs in the future. An expert on the subject, Idoia Salazar, president and founder of the Observatory of the Social and Ethical Impact of Artificial Intelligence (Odiseia), has stressed that "we must learn to live" with this technology and "put certain ethical standards so that this coexistence be healthy.”

At this point, our code should look as shown below. The number of paragraphs can be whatever we want, depending on whether we have made our divisions.

It is advisable for text that is going to be read on the screen, that we give rest to the reading with more or less short paragraphs (unlike paper, reading on the screen has a different speed for the human eye and is much more tiring). It is also not necessary for the text to look like a telegram, let's not go overboard. I leave it to your free will, but it should be something like this:

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-1.html

<html>

    

The boom of AI in consumer technologies

The AI boom refers to an ongoing period of rapid and unprecedented development in the field of artificial intelligence, with the generative AI race being a key component of this boom, which began in earnest with the founding of OpenAI. in 2016 or 2017¹.

AI is already the main driver of emerging technologies such as big data, robotics and IoT, not to mention generative AI, with tools such as ChatGPT and AI art generators gaining widespread attention, and will continue to act as a technological innovator in the foreseeable future.

In the short term, generative AIs can already answer questions, write poetry, generate computer code, and hold conversations. They are being implemented in conversational formats such as ChatGPT and Bing. But that won't last long. Microsoft and Google have already announced plans to incorporate these AI technologies into their products. You can use them to draft an email, automatically summarize a meeting, and perform many other cool tricks.

In the medium term, many experts believe that AI will make some workers, including doctors, lawyers and computer programmers, more productive than ever.

They also believe some workers will be replaced. "This will affect tasks that are more repetitive, more formulaic, more generic," said Zachary Lipton, a professor at Carnegie Mellon who specializes in artificial intelligence and its impact on society. "This may free up some people who are not good at repetitive tasks. At the same time, there is a threat to people who specialize in the repetitive part."

As for the long term, it is difficult to predict exactly what this technology will have in store for us. However, it is clear that AI is constantly changing our world and will continue to do so in the future.

What could the future of humanity hold for us living with AI.

There are many hypotheses and ideas about what it will be like to live with AIs in the future. An expert on the subject, Idoia Salazar, president and founder of the Observatory of the Social and Ethical Impact of Artificial Intelligence (Odiseia), has stressed that "we must learn to live" with this technology and "put certain ethical standards so that this coexistence be healthy.”

As far as science fiction ideas go, there are many films that explore the theme of artificial intelligence and how it could affect our lives in the future.

For example, in the movie "Her" (2013), the protagonist falls in love with an operating system voiced by Scarlett Johansson.

In "The Matrix" (1999), humans are controlled by evil machines.

In "Ex Machina" (2015), a programmer is invited to administer a Turing test to a humanoid robot with advanced artificial intelligence.

</html>

Finishing structuring the HTML document is vital so that it is interpretable properly for a web browser. We are going to add the minimums, that is, within the html document, add and separate the header data (head) from the document body data (body). A well-structured web page must have its HEAD part and its BODY part. Until now, we had simply been adding things within the html tag, our titles and paragraphs. If we preview the previous code in the browser, it will be displayed as is, nothing happens, there is no error message (html never gives errors, simply a website is fine, or it is not, it looks good, or it doesn't look good. )

Below I add the structure that is missing from the document, and I summarize what we have done using comments; This way we will have a more global view of the document:

<html Lang="is">

  <head>
    </html></span><span style="color: #D8DEE9FF">The boom of AI in consumer technologies</span><span style="color: #81A1C1">
    <meta yam="description" content="How artificial intelligence has burst into our daily lives, and what we can obtain from them in the near future">
  </head>
  
  <body>
  
    

The boom of AI in consumer technologies

The boom in artificial intelligence refers to...

Our 2nd level subtitle...

(...) to a humanoid robot with advanced artificial intelligence.

</body> </html>

Note that so that you have better readability, and for a better visual reference of "where" and "to where" the labels go, as well as "what goes inside what", I am making use of tabs, and some jumps of extra line.

When you work with code, this is sacred so as not to end up with presbyopia. Not only must you know at all times how you are "nesting" the labels, but you must also be as neat as possible for when you return to this project and must reposition yourself. It could be you or, in the work context, another person.

No matter how simple a representation markup language like HTML may be, in which, as we mentioned, there is no programmatic logic, when there are many marks and a lot of content, it can become convoluted.

That said, let's analyze the previous fragment. Let's go first with the HEAD part and an addition that I have put in the initial HTML tag:

<html Lang="is">

  <head>
    </html></span><span style="color: #D8DEE9FF">The boom of AI in consumer technologies</span><span style="color: #81A1C1">
    <meta yam="description" content="How artificial intelligence has burst into our daily lives, and what we can obtain from them in the near future">
  </head>
  
  <body>

In HTML I have added the lang=»es», to tell the browser that the content of this page is in Spanish. This is necessary, although it seems very automatic, which should be like autodetection, we must say in what language what is written is.

Right below we have added the HEAD. Between and , are added:

  • Metadata of the document, data NOT directly visible on the web page, but that helps to classify the information.
  • CSS language styles required for the correct display of the HTML document. These can be written directly into the file, like the rest of the text, or linked to an external file.
  • Javascript language scripts: Javascript is the programming language that Internet browsers interpret to apply logic and interactivity to HTML web pages. Like CSS, scripts can be written in the same file.

Let's go with the first, and then with the second, we are going to leave the third for now, since for our layout at the moment scripts are not necessary.

HEAD metadata

The metadata is not visible on the page. They will not appear in our design. Imagine that the page is a closed dossier in a file in a megalibrary. Well, the metadata would be a label in the dossier, the typical little tab that stands out in a classifier.

Thanks to the metadata, and in combination with the context and content of the article that the web page contains, it can be found automatically by search engines (They are like Google, but there are thousands of them 😁).

I have added, as you can see, title (which is a tag with opening and closing) and the meta description; METAs do not have a closure in their syntax, they are used like this:

<meta yam="description" content="Short and concise description of the page content">

Where is this information seen?

On the one hand, the TITLE (which can be the same or different from what we have put in the H1 tag) will appear in the browser tab when we have the document or page loaded open. It will also be used as the name of the "bookmark" if we add the page to our favorites:

Example of how the title tag is seen in the browser tab and in bookmarks

On the other hand, if our site is indexed by search engine robots, which crawl the web as if they were millions of spiders moving through the global web of the Internet, our title and description would appear like this in the results of a search:

The page that a search engine returns to us when we have made a query, the results page, is called by the acronym SERP (Search Engine Result Page). And the little piece that we show with our title and meta description is the SERP Snippet.

Many people believe that this snippet is generated automatically, but this is not entirely true. I won't delve into the topic today, but get used to the idea that adding TITLE and META DESCRIPTION at a minimum to your page's metadata is SACRED.

Returning to the layout: The LAYOUT of the document

Having understood the not directly visible part of the website, we return to our document, which currently, if we open it with the browser, looks more or less like this:

Poor design, right? Well, one thing that is certain is that it is perfectly readable. But what the browser is doing is using some style rules that are built in by default (and depending on the browser, these may differ slightly). These rules are therefore a default font (Times New Roman or "serif font") and pre-assigned font sizes, line spacing and bodies (normal, bold) for paragraphs and titles. Default text alignment to the left, and as you can see, no margin or maximum paragraph length (which is VERY annoying)

Did you know? The lines of text should not contain more than approximately 13-15 words, because otherwise the person will get lost and have a hard time knowing which line they were on.

game building blocks nanoblocks

#loNeed #buildingBlocks #buildCheaper

How fonts work on web pages

Basically, for the browser to be able to display the page in a specific font, this font must be installed on the computer or phone from which the page is being requested.

The Times font or a similar type always comes pre-installed on any operating system (Windows, Apple, Linux, Android...).

If we now went to our file explorer, and deleted this font, the browser would use another available one.

This is called "fallback"; We can tell you, in our CSS styling language:

«We are going to use this font, and if it is not there, use this other one, and if not, this other one, and if not, finally the one you find available»

What we do here is define a FONT-STACK, or a stack of fonts to use.

Getting started with CSS

We are going to add in the HEAD part of the code, before the closure of HEAD, the tag </head> <body>

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-2.html

What we do here is define a font family with its stack of common fonts, in this case sans serif or sans serif fonts (I'll give you the details in another post with the letter families), for the HTML root tag.

We tell the document to use the "layout flex" mode, which allows us to tell the content blocks to be justified centered. This alignment method is for blocks, it has nothing to do with text alignment, this is important to distinguish.

On the other hand, I have told the entire ARTICLE article to make it at most 800 pixels wide*. So that the lines are not so, so long and tedious. Notice how the command justify-content:middle now centers the entire block of text, but its alignment does not center (because we left the text aligned to the left).

* You can use other units of measurement, percentage, VW/VH… There is a very interesting one that is the CH (characters), for example width:60ch, it will make it a paragraph block "60 letters" of the current size.

Click on the previous image to preview in the browser what has been achieved so far. I recommend that you try stretching and narrowing the window, so you can see the behavior of the text adjustment. You must be clear that you never know what screen size people will see your website on. So it has to be able to look good at any size.

Improving text formatting

The thing is that on the one hand, I am old enough and I am myopic; On the other hand, I like designs with strength and forcefulness. But you should be clear about one thing: When we read things on the screen, we do it faster and faster, diagonally, and skipping paragraphs. It is unconscious, but it is scientifically proven. So, if you want to be read, you will have to use certain strategies in your design.

Let's add a couple more rules to the base CSS of the html document:

  

Now I'm going to put a before and after adding this new text size and line-height so you can see the difference and tell you what happened:

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-3.html

I have increased the text of the paragraphs to 18 pixels, and I have given a very generous line spacing, from 200%. The css line line-height:2 is telling you to use twice your base height. For both font-size and line-height we can use different units, both px and others, or percentages. Also to refine better, we can use decimals using the point (Example: line-height: 126.7% ). Here I let you do your tests. It's how you learn.

Now, if you look at the before and after screenshots, apart from the fact that it is much more spaced, the document has become taller, of course, because we have doubled the vertical space.

But if you look at the headers (H1 and H2), their size has not changed. This is because P, or paragraph, does not currently have any specified rule, nor do we need it in this case, so it INHERITS the text properties that we defined in the "parent" tag, which is HTML.

On the other hand, the headers have the sizes specified for each one (h1 being the largest, h2, h3 etc. increasingly smaller, to maintain a visual hierarchy of sections).

As I said, I personally like the forceful. Let's introduce some powerful sizes for the headers:


In the headers, apart from the size, I specify a line-height again. If I didn't, the 200% that I specified for the HTML tag would be applied, which looks very bad in very large texts (the line height takes up too much space, which is why I have reduced it.)

Although we are improving in the layout, this article is still visually boring, and does not invite reading. Let's give it some life, to begin with, let's make the first paragraph after the first title larger and make us less lazy to start reading.

Now, in CSS, since I want to apply a style to only one paragraph, I'm going to make a new rule called "intro." It's a name that I made up. For this, we are going to create a CLASS. Attention:

<style>
  /* ... rest of the code */
      h2 {
        font-size: 175%;
        line-height: 1.3;
      }
      
      .intro {
        font-size:150%;
        line-height:1.5;
        color:steelblue;
      }
  </style>

I will apply this new rule to the first paragraph, which will make the text a little larger and it will also be metallic blue. For color nomenclature, you can use color names in English, or several different color codings, as this tutorial is for beginners, it is better to use a color from the available list. See available colors for html/css.

This is a resource to give a little life. We will add the "intro" style to the first paragraph like this:

  

The boom of AI in consumer technologies

<p class="intro">The boom in artificial intelligence refers to a ongoing period of rapid and unprecedented development in the field of artificial intelligence, with the generative AI race being a key component of this boom, which began in earnest with the founding of OpenAI in 2016 or 2017¹.

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-4.html

Next, I'm going to do 2 things:

Highlight names and relevant parts in paragraphs in bold; The bold type invites that if someone reads us very quickly and skips things, it captures their attention more to stop and read. To mark parts in bold, we will use the STRONG tag like this:

AI is already the main driver of emerging technologies such as big data, robotics and IoT, not to mention generative AI, with tools like ChatGPT and AI art generators gaining widespread attention, and will continue to act as a technological innovator for the foreseeable future.

In the short term, generative AIs can already answer questions, write poetry, generate computer code, and hold conversations. They are being implemented in conversational formats such as ChatGPT and Bing. But that won't last long. Microsoft and Google They have already announced plans to incorporate these AI technologies into their products. You can use them to draft an email, automatically summarize a meeting, and perform many other cool tricks.

In the medium term, many experts believe that AI will make some workers, including doctors, lawyers and computer programmers, be more productive than ever.

Create a large quote phrase or “magnifying glass” phrase; We will copy some part of the text and we will put it between paragraphs as a highlighted phrase. From the previous fragment, I like the last sentence, for example. I am going to duplicate it (without the STRONG tag that I have placed and removing "Many experts believe" from the beginning, to summarize it) and I am going to place it between the second and third paragraph:

AI is already the main driver of emerging technologies such as big data, robotics and IoT, not to mention generative AI, with tools like ChatGPT and AI art generators gaining widespread attention, and will continue to act as a technological innovator for the foreseeable future.

Many experts believe that AI will make some workers, including doctors, lawyers and computer programmers, more productive than ever.

In the short term, generative AIs can already answer questions, write poetry, generate computer code, and hold conversations. They are being implemented in conversational formats such as ChatGPT and Bing. But that won't last long. Microsoft and Google They have already announced plans to incorporate these AI technologies into their products. You can use them to draft an email, automatically summarize a meeting, and perform many other cool tricks.

In the medium term, many experts believe that AI will make some workers, including doctors, lawyers and computer programmers, be more productive than ever.

Now we will get this:

By default, our highlighted sentence only stands out because it has some margin on the left. Now, let's add some styling to our CSS for this tag:

<style>
 /* ... */
   blockquote {
      font-size: 125%;
      line-height: 1.6;
      color: steelblue;
      margin: 20px 10%;
   }
 </style>

I have increased the text size and adjusted the line spacing; I have given it the color of the entry, and I have modified its margins; Before, by default the BLOCKQUOTE had a margin of 20px on all 4 sides; adding the 20px 10% parameter, I have told it to have 20px top and bottom vertically, and horizontally a 10% of the total space of the block (in this case, a 10% of the width of the article).

I mean, a little bigger, colored and centered. To top things off, I like highlighted phrases in quotation marks, they help make it clear that it is a quote and not a title. I'm going to add them at the beginning and at the end; but instead of using the standard vertical double quotes ( » ), I want to use the ones that are slanted on either side ( " and " ). Since I don't remember how to get those special quotes with the keyboard, I'm going to use HTML ENTITIES. Specifically for those quotes they are «"" for the left, and """ to the right:

&ldquo; Many experts believe that AI will make some workers, including doctors, lawyers and computer programmers, more productive than ever. &rdquo;

Resource: Here is a list of types of quotes that we can use, I am very sybarite.

Okay, well, I have put that highlighted phrase, and another one a little further down, to remove monotony to the rhythm of the paragraphs.

HTML text with two stylized blockquote tags

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-5.html

Illustrate the article: add a header photo, and another for the content

Let's just add life to the article by adding images. Without going too far, I am going to choose 2, one we will put at the very top, very large, the other I will place over the second title. This way it will also act as a separator for the 2 parts that make up the article. I've looked for a couple of free photos like this in a shabby futuristic cyber style on freepik.es:

I recommend choosing somewhat landscape images. I have cropped them using Photopea's cropping tool, a fairly handy online Photoshop substitute. I will use the most horizontal one for the header.

The tag to insert an image is IMG and it is a self-closing tag. (you don&#039;t have to close it with </img>). It is used like this:

<img src="file-path/file.jpg" alt="logical description of the image" width="width" height="height">

SRC

It is the file path. If you are doing the exercise on your computer, and you place the image in the same folder where you have your html, you have to put the name of the file (with the extension, .png, .jpg, etc.) without further ado. If you have the image in a subfolder with respect to your html, then the path will be foldername/filename.html. As I upload it to my website to make this tutorial for you, I will put its full url path.

ALT

You can skip it when you do tests, but once online this is essential and mandatory: Describe what that image is. Because the browser does NOT know what the image is, and it must know in order to be able to describe it to the user, whether or not they can load it. It is a logical description, the text is NOT a caption where comments should be added, if it is a photo of a dachshund, its ALT will be "photograph of a dachshund."

WIDTH AND HEIGHT

Width and height of the image in pixels, percentage (of its available contextual space) or with the value "auto". If both values are "auto", the image will be rendered in its original measurements. If, for example, we specify "500" for width and "auto" for height, the image will be scaled to 500 width, without being distorted.

We can specify a size larger than the original image, but it is never recommended because its pixels and defects will be stretched and it will look blurry.

The browser before and during loading the images will reserve the space that we specify in width and height, but these values can be controlled from the CSS styles, where we have more resources for the behavior of the images. Then we see it.

I'm going to put the photo of the header here, before the H1:

    
<img src="https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/concepto-digital-ai-freepik.jpg" alt="digital world conceptual illustration" width="100%" height="car">

The boom of AI in consumer technologies

And the other photo, I place it here, before the second title of the article:

(...) and will continue to do so in the future.

<img src="https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/hombre-usando-tableta-freepik.jpg" alt="man using digital tablet" width="100%" height="car">

What could the future of humanity hold for us living with AI.

If the image paths are correct, this will be what comes out:

https://cachitoswp.com/tutoriales/maquetacion-articulo-html-css/maquetacion-articulo-html-css-6.html

Et voila! Well, not that bad, right? We have a layout, illustrated, colorful and attractive little article, and we have done it using HTML AND CSS. Congratulations.

We will use this same article in future tutorials to practice playing with the widths, varying the columns, and I will teach you how to make the layout of the page responsive and adapt correctly to small screens such as those of smartphones.

Right now, as is the page, it can be viewed on a smartphone, but if you try it, you will see that it is displayed to scale, just as you see it on the computer. You can zoom in and read the article (which is not bad and makes it accessible), but it is not the most convenient.

You'll see how beautiful this responsive thing is, in the second part of this tutorial. See you!


Last bits

Decorative image title comments

Leave a Reply

Your email address will not be published. Required fields are marked *