Markup Languages: A Beginner’s Guide to Curly Braces

Published on Dec 27, 2025
Updated on Dec 27, 2025
reading time

Markup languages and curly braces

In the vast world of the web, markup languages play a fundamental role. They are like the foundation of a house, invisible but essential for the structure and appearance of every web page. In this guide, we will focus on a key element of these languages: curly braces. You will learn in a simple and clear way how to use curly braces in HTML, CSS, and JSON, three pillars of the modern web.

What Are Markup Languages?

A markup language is a set of rules for annotating a text with additional information about its structure and formatting. Imagine you want to write a letter and want to highlight some words in bold or in italics. In a markup language, you would use specific tags to tell the computer how to display the text.

Advertisement

Common examples of markup languages are:

  • HTML (HyperText Markup Language): the main language for creating web pages.
  • XML (Extensible Markup Language): a more flexible and customizable language.

Unlike programming languages, which are used to create programs and applications, markup languages describe content and its presentation. HTML, CSS, and JSON are three fundamental markup languages for web development.

Read also →

Curly Braces in HTML

Markup Languages: A Beginner's Guide to Curly Braces - Summary Infographic
Summary infographic of the article “Markup Languages: A Beginner’s Guide to Curly Braces”
Advertisement

In HTML, curly braces {} have a limited role. They are mainly used within the style attribute to define the styles of an element directly in the HTML code.

Here is an example:

HTML

<p style="color: blue; font-size: 16px;">This text is blue and has a size of 16 pixels.</p>

In this case, the curly braces enclose the CSS style declarations that define the color and size of the text.

Practical Exercises on HTML

  1. Create a paragraph in HTML and use the style attribute with curly braces to make it red and bold.
  2. Modify the HTML code of an existing web page and add an inline style using curly braces to change the background color of an element.
Discover more →

Curly Braces in CSS

Curly braces symbol on HTML and CSS code background
Curly braces define the structure and style of modern web pages.
Advertisement

In CSS (Cascading Style Sheets), curly braces are fundamental. They serve to enclose the style declarations that define the appearance of HTML elements.

The CSS syntax is simple:

CSS

selector {
  property: value;
  property: value;
  ...
}
  • The selector indicates the HTML element to which the styles apply (for example, p for paragraphs, h1 for headings).
  • The declarations define the style properties and their values (for example, color: blue; for the text color).
  • The curly braces enclose all style declarations that apply to the selector.

Here is an example:

CSS

p {
  color: red; 
  font-size: 14px;
  font-weight: bold;
}

This CSS code will make all paragraphs on the web page red, with a size of 14 pixels, and bold.

Practical Exercises on CSS

  1. Create a CSS stylesheet and define a style for h2 headings that makes them blue and centered.
  2. Experiment with different CSS properties and values to modify the appearance of an HTML element.
Discover more →

Curly Braces in JSON

JSON (JavaScript Object Notation) is a lightweight format for data interchange. It is often used to transmit data between a server and a web client.

In JSON, curly braces define objects. An object is a collection of key-value pairs.

Here is an example:

JSON

{
  "name": "Mario",
  "surname": "Rossi",
  "age": 30
}

In this case, “name”, “surname”, and “age” are the keys, while “Mario”, “Rossi”, and 30 are the values.

Curly braces in JSON can also define arrays, which are ordered lists of values.

Practical Exercises on JSON

  1. Create a JSON file representing a book with the following information: title, author, year of publication.
  2. Use a text editor or an online JSON validator to verify the correctness of your JSON code.
Read also →

Curly Braces and JavaScript

JavaScript is a programming language that adds interactivity to web pages. In JavaScript, curly braces play an important role in defining code blocks and objects.

  • Code blocks: curly braces enclose code that must be executed together, such as in a function or a loop.
  • Objects: in JavaScript, objects are similar to those in JSON, but they can also contain functions.

Here is an example of an object in JavaScript:

JavaScript

var person = {
  name: "Mario",
  surname: "Rossi",
  age: 30,
  greet: function() {
    alert("Hello, my name is " + this.name);
  }
};

Practical Exercises on JavaScript

  1. Write a simple function in JavaScript that uses curly braces to define a code block.
  2. Create an object in JavaScript representing an animal with properties like name, species, and sound.
You might be interested →

The Importance of Indentation

Indentation, which is the addition of spaces or tabs at the beginning of lines of code, is fundamental for readability, especially when using curly braces. Well-indented code is easier to read, understand, and modify.

There are different indentation styles, but the important thing is to be consistent.

Here is an example of well-indented CSS code:

CSS

body {
  font-family: sans-serif;
  margin: 0;
}

h1 {
  color: blue;
  text-align: center;
}
Discover more →

Code Validation

Validating HTML, CSS, and JSON code is important to ensure it is correct and error-free. Validation can identify errors in the use of curly braces, missing or incorrectly closed tags, and other syntax issues.

There are several free online tools to validate code:

You might be interested →

Common Mistakes with Curly Braces

Here are some common mistakes beginners might make when using curly braces:

  • Missing or mismatched curly braces: ensure that every open curly brace has a corresponding closing curly brace.
  • Syntax errors: respect the specific syntax of each language (HTML, CSS, JSON).
  • Incorrect indentation: incorrect indentation can make the code difficult to read and debug.
You might be interested →

Useful Tools for Working with Markup Languages

To work with markup languages, it is useful to use specific tools:

  • Code editors: software that offers features like syntax highlighting, autocomplete, and code validation (examples: Visual Studio Code, Sublime Text, Atom).
  • Validators: online tools or tools integrated into code editors that verify the correctness of the code.
  • Debuggers: tools that help identify and fix errors in the code.

Use of Curly Braces in HTML, CSS, and JSON

LanguageUse of curly bracesExample
HTMLDefinition of inline styles in the style attribute.<p style="color: blue;">Blue text</p>
CSSEnclosing style declarations for a selector.p { color: red; font-size: 14px; }
JSONDefinition of objects and arrays.{ "name": "Mario", "age": 30 }
  1. Apply HTML inline styles

    Use curly braces within the style attribute of HTML tags to define immediate visual properties like color or dimensions.

  2. Define CSS rules

    In the stylesheet, use braces after each selector to enclose the block of declarations that modify the appearance of elements.

  3. Structure data in JSON

    Employ curly braces to delimit objects in JSON format, containing the key-value pairs necessary for data exchange.

  4. Write JavaScript logic

    Leverage braces in JavaScript to define the body of functions, loops, conditional statements, and to create complex objects.

  5. Maintain indentation

    Improve code readability by inserting consistent spaces or tabs within blocks delimited by curly braces.

  6. Validate the code

    Check that you have correctly closed all curly braces using specific online validators for HTML, CSS, or JSON to avoid errors.

In Brief (TL;DR)

Curly braces are essential elements in HTML, CSS, and JSON. In HTML, they are mainly used to define inline styles.

In CSS, they enclose style declarations. In JSON, they define objects and arrays.

Mastering the use of curly braces is fundamental for writing correct and readable code.

Advertisement

Conclusions

disegno di un ragazzo seduto a gambe incrociate con un laptop sulle gambe che trae le conclusioni di tutto quello che si è scritto finora

In this journey into the world of markup languages, we explored the importance of curly braces in HTML, CSS, and JSON. We saw how these apparently simple symbols are fundamental for structuring code, defining styles, and organizing data.

Mastering the use of curly braces is just the first step in your learning path. The world of web development is constantly evolving, with new languages and technologies emerging constantly. Continue to explore, experiment, and learn to refine your skills and create increasingly innovative and engaging web pages.

To stay updated on the latest news in the IT field, subscribe to the TuttoSemplice.com newsletter.

Frequently Asked Questions

disegno di un ragazzo seduto con nuvolette di testo con dentro la parola FAQ
What is the difference between curly braces and square brackets in JSON?

Curly braces {} define objects, while square brackets [] define arrays.

Can I use curly braces in HTML to insert comments?

No, in HTML comments are inserted between /* */.

How can I learn more about markup languages?

There are many online resources, such as tutorials, courses, and forums, that can help you deepen your knowledge.

Is it necessary to indent the code?

It is not mandatory, but indentation makes the code much more readable and easier to maintain.

What are the best tools to validate code?

There are several free online tools, such as the W3C HTML validator and JSONLint.

Francesco Zinghinì

Electronic Engineer with a mission to simplify digital tech. Thanks to his background in Systems Theory, he analyzes software, hardware, and network infrastructures to offer practical guides on IT and telecommunications. Transforming technological complexity into accessible solutions.

Did you find this article helpful? Is there another topic you’d like to see me cover?
Write it in the comments below! I take inspiration directly from your suggestions.

Icona WhatsApp

Subscribe to our WhatsApp channel!

Get real-time updates on Guides, Reports and Offers

Click here to subscribe

Icona Telegram

Subscribe to our Telegram channel!

Get real-time updates on Guides, Reports and Offers

Click here to subscribe

Advertisement
Condividi articolo
1,0x
Table of Contents