KevsRobots Learning Platform
By Kevin McAleer, 2 Minutes

Jekyll’s layouts and includes are powerful tools that allow you to abstract common website elements and reuse them across your site. This not only makes your site more consistent but also significantly speeds up development and maintenance.
Layouts are templates that wrap around your content. They’re used to define a common structure for your pages or posts.
_layouts directory.default.html.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ page.title }}</title>
</head>
<body>
{{ content }}
</body>
</html>
In this example, {{ page.title }} dynamically inserts the title of the page or post using it, and {{ content }} is where Jekyll inserts the content from your Markdown file.
In your Markdown file’s front matter, specify the layout you want to use:
---
layout: default
title: My First Post
---
Includes allow you to insert snippets of code into your layouts or content. They’re perfect for reusable components like headers, footers, and navigation bars.
_includes directory.header.html.
<header>
<nav>
<ul>
<li><a href="{{ site.baseurl }}/about">About</a></li>
<li><a href="{{ site.baseurl }}/contact">Contact</a></li>
</ul>
</nav>
</header>
To use an include in a layout or another include, use the include tag:
{% include header.html %}
default layout that includes a basic HTML structure.header.html and footer.html include for navigation and footer content, respectively.default layout and includes your header and footer. Make sure this page contains some basic content to demonstrate the layout and includes in action.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments