Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

block Template Tag


Example

Define a section in a master template that should be replaced by a section in a child template:

<!DOCTYPE html>
<html>
<body>
<h1>Welcome</h1>

{% block userinfo %}
  <h2>Not registered yet</h2>
{% endblock %}

</body>
</html>
Run Example »

Definition and Usage

The block tag  has two functions:

  1. It is a placeholder for content.
  2. It is content that will replace the placeholder.

In master templates the block tag is a placeholder that will be replaced by a block in a child template with the same name.

In child templates the block tag is content that will replace the placeholder in the master template with the same name.

In the example above you see the content of a master template, it has a block called userinfo. This block will be replaced with a block called userinfo in a child template:

Example

This is a child template that refers to a master template via the extend tag:

{% extends "mymaster.html" %}

{% block userinfo %}
  <h2>John Doe</h2>
  <p>Explorer of life.</p>
{% endblock %}
Run Example »

Syntax

{% block name %}
  ...
{% endblock %}

Parameters

Value Description
name Specifies that name of the block.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.