Header template
Third party applications and systems should use a consistent Cardiff.gov branded banner and page layout where possible.
The aim is to provide as consistent experience for the customer as possible.
How to use this component
We have provided boilerplate html code that you can use to skin your application.
You can find the html, css and Javascript below.
We have hosted a css file that contains our cardiff.gov styling.
Icons rely on FontAwesome, you will need to ensure this is hosted on your system and referenced in the template with the following font types:
- Regular
- Solid
- Brands
View a working example
Code Resource
<a href="#main" class="skip-link">Skip to main content</a>
<header class="header">
<div class="header__utilities">
<div class="container">
<ol class="utilitymenu utilitymenu--top" aria-label="top utilities navigation">
<li class="utilitymenu__item"><a href="/accessibility" class="utilitymenu__link">Accessibility</a></li>
<li class="utilitymenu__item">
<a href="#" class="utilitymenu__link" lang="cy">Cymraeg<span class="sr-only"> (External link)</span></a>
</li>
</ol>
</div>
</div>
<div class="header__actions">
<div class="container">
<div class="gi-sitelogo gi-sitelogo--header">
<a href="/" class="gi-sitelogo__link"
><span class="sr-only">Cardiff Council home</span
><img
src="https://cardiffassets.blob.core.windows.net/general/CardiffCouncilDragon.svg"
width="164"
height="192"
alt=""
class="gi-sitelogo__image"
/></a>
</div>
</div>
</div>
<!-- Menu now lives inside the header so the toggle and dropdown anchor to it -->
<div id="cc_menu_nav">
<button type="button" class="menu-toggle" aria-expanded="false" aria-controls="main-nav" aria-label="Menu"><span aria-hidden="true">☰</span></button>
<nav id="main-nav" class="mega-nav nu_menu" aria-label="Main navigation">
<ul>
<li><a href="https://www.cardiff.gov.uk/" class="menu_back">Back to Cardiff.gov</a></li>
<li><a href="#">Menu 1</a></li>
<li class="has-submenu">
<a href="#" class="submenu-link">Menu 2</a>
<button type="button" class="submenu-toggle" aria-expanded="false" aria-controls="sub-menu2"><span class="sr-only">Menu 2 submenu</span></button>
<ul id="sub-menu2" class="submenu" hidden>
<li><a href="#">Sub menu 1</a></li>
<li><a href="#">Sub menu 2</a></li>
<li><a href="#">Sub menu 3</a></li>
</ul>
</li>
<li><a href="#">Menu 3</a></li>
</ul>
</nav>
</div>
</header>
<main id="main" tabindex="-1">
<div class="content">
<h1>Page title</h1>
<p>Content is centered with a max-width of 1500px.</p>
<p>Please note for the icons to work you must <a href="https://fontawesome.com/start" target="_blank" rel="noopener">create a font awesome kit<span class="sr-only"> (opens in a new tab)</span></a> and include the file in the header.</p>
</div>
</main>
<script src="menu.js"></script>
:root {
--cc-teal-dark: #0b616d;
--cc-teal-main: #076e7c;
--cc-teal-content-text: #00525f;
--cc-teal-hover: #004355;
--cc-teal-darker: #01383f;
--cc-orange-warning: #AC6616;
--cc-grey-light: #e5e5e5;
--cc-grey-panel-bkgrnds: #f6f6f6;
--cc-grey-mid: #c4c4c4;
--cc-grey-dark: #232323;
--cc-red-focus: #ae0e00;
--cc-blue-focus: #023d54;
--cc-font-family-text: "Inter", sans-serif;
--cc-font-family-icons: "Font Awesome 6 Free";
}
/* Standard visually-hidden pattern (still read by screen readers) */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
/* Skip link, visible on keyboard focus */
.skip-link {
position: absolute;
left: 8px;
top: -100px;
z-index: 1000;
background: #fff;
color: var(--cc-teal-content-text);
padding: 10px 16px;
font-weight: 600;
}
.skip-link:focus {
top: 8px;
}
body {
font-family: var(--cc-font-family-text);
margin: 0px;
}
h1,
h2,
h3,
h4 {
color: var(--cc-teal-content-text);
font-weight: 400
}
h1,
h2 {
font-size: 1.6em
}
h3 {
font-size: 1.2em
}
p {
line-height: 1.4em
}
ul,
ol {
list-style: none;
}
a {
color: var(--cc-teal-content-text);
}
a:hover {
color: #000;
}
.header {
background-color: var(--cc-teal-main);
position: relative;
/* anchors the mobile toggle and dropdown */
}
.header .container {
max-width: 2000px
}
.header__actions {
padding: 10px 0
}
.header__utilities {
background-color: transparent;
position: absolute;
right: 0
}
.header__utilities .container {
padding: 0
}
.utilitymenu--top {
background: var(--cc-teal-dark)
}
.utilitymenu--top .utilitymenu__item {
margin: 0;
padding: 5px;
font-size: 1em;
color: #fff;
position: relative;
z-index: 1
}
.utilitymenu--top .utilitymenu__item:hover,
.utilitymenu--top .utilitymenu__item:focus {
color: #fff
}
.utilitymenu--top .utilitymenu__item:last-child {
margin: 0;
padding-right: 10px
}
.utilitymenu--top .utilitymenu__item:not(:last-child).utilitymenu__item {
padding-right: 0
}
.utilitymenu__link {
color: #fff
}
.utilitymenu__link:hover,
.utilitymenu__link:focus,
.utilitymenu__link:active {
color: #fff
}
.utilitymenu__link:hover,
.utilitymenu__link:focus {
text-decoration: underline;
text-underline-offset: .3em;
text-decoration-thickness: 2px
}
.utilitymenu.utilitymenu--mobile {
border-top: 2px solid var(--cc-grey-light)
}
.utilitymenu__link,
.utilitymenu__text {
padding: 12px 8px 12px 8px;
display: block;
text-decoration: none;
}
.utilitymenu__link:focus,
.bygoss a:focus,
.imagelink__link:focus {
outline: 3px solid #fff;
outline-offset: 0;
box-shadow: 0 6px #050505, 0 3px #0b0c0c
}
.header__actions {
padding: 8px 0
}
ol.utilitymenu.utilitymenu--top {
display: flex;
flex-direction: row;
margin-top: 0px;
padding-left: 5px;
}
ol.utilitymenu.utilitymenu--top li:first-child {
border-right: 1px solid var(--cc-teal-hover)
}
.sitemenu--mobile {
background-color: var(--cc-teal-main)
}
.utilitymenu--mobile .utilitymenu__link,
.utilitymenu--mobile .utilitymenu__text {
border-bottom: 1px solid var(--cc-teal-darker);
background-color: var(--cc-teal-main)
}
.gi-sitelogo__image {
height: 55px !important;
width: auto;
margin-right: 23px;
margin-left: 20px;
}
.gi-sitelogo__link:focus-visible {
outline: 3px solid #fff;
outline-offset: 2px;
}
/* Text next to the logo (now shown at all screen sizes) */
.gi-sitelogo::after {
content: "Cardiff Council";
content: "Cardiff Council" / "";
/* decorative: empty alt text so screen readers skip it */
color: #fff;
font-weight: 200;
font-size: 1.1em;
position: absolute;
margin-top: 10px;
font-family: var(--cc-font-family-text)
}
.gi-sitelogo__link::after {
content: "www.cardiff.gov.uk";
content: "www.cardiff.gov.uk" / "";
/* decorative: empty alt text so screen readers skip it */
color: var(--cc-grey-light);
font-size: .75em;
position: absolute;
margin-top: 32px;
font-family: var(--cc-font-family-text)
}
/* ### Menu ### */
#cc_menu_nav {
width: 100%;
background: var(--cc-teal-dark);
border-top: 1px solid var(--cc-teal-darker);
display: flex;
align-items: center;
position: relative;
min-height: 47px
}
.menu-toggle {
display: none;
font-size: 1rem;
padding: 1rem;
background: var(--cc-teal-dark);
color: #fff;
border: 0;
height: 100%;
cursor: pointer;
}
/* Menu */
.nu_menu {
background-color: #0b616d !important;
border-top: 0px solid #0b5560;
color: white !important;
float: left !important;
width: 100% !important;
font-size: 1em;
}
.nu_menu ul,
.nu_menu li {
list-style: none;
margin: 0px;
padding: 0px;
}
.nu_menu a {
color: white !important;
margin-right: 1px;
margin-top: 1px;
margin-bottom: 1px;
padding-left: 30px !important;
padding-right: 30px !important;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
transition: all 0.3s ease;
font-size: 0.85em;
padding: 8px;
border-right: 1px solid #0b5560;
float: left;
text-decoration: none;
}
.menu_back:before {
content: "\f053";
content: "\f053" / "";
/* decorative icon: empty alt text so screen readers skip it */
font-family: "Font Awesome 5 Pro";
font-weight: 600;
margin-right: 10px;
}
.nu_menu a:hover {
text-decoration: underline;
text-underline-offset: .3em;
}
/* Submenu: the top-level item is a normal link, with a separate chevron button beside it */
.nu_menu .submenu-link {
padding-right: 8px !important;
border-right: 0;
}
.nu_menu .submenu-toggle {
background: none;
border: 0;
border-right: 1px solid #0b5560;
color: #fff;
font: inherit;
padding: 8px 20px 8px 10px;
margin: 1px 1px 1px 0;
cursor: pointer;
}
.nu_menu .submenu-toggle:hover {
background: rgba(255, 255, 255, .12);
}
/* chevron (decorative, no text so nothing for screen readers to read) */
.nu_menu .submenu-toggle::after {
content: "";
display: inline-block;
width: .45em;
height: .45em;
border: solid currentColor;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
position: relative;
top: -.15em;
transition: transform .2s ease;
}
.nu_menu .submenu-toggle[aria-expanded="true"]::after {
transform: rotate(-135deg);
top: .1em;
}
.submenu[hidden] {
display: none !important;
}
/* Visible keyboard focus (inset so it isn't clipped) */
.nu_menu a:focus-visible,
.nu_menu .submenu-toggle:focus-visible,
.menu-toggle:focus-visible {
outline: 3px solid #fff;
outline-offset: -3px;
box-shadow: inset 0 0 0 5px var(--cc-teal-darker);
}
main {
margin-top: 30px;
float: left;
width: 100%;
}
main:focus {
outline: none;
/* main is only focused by the skip link */
}
.content {
max-width: 1500px !important;
margin-right: auto;
margin-left: auto;
padding: 10px 6%;
}
/* ### Media queries (one of each, kept together at the end of the file) ### */
/* ### Desktop: menu bar with flyout submenu ### */
@media (min-width: 1024px) {
.nu_menu>ul {
display: flex;
flex-wrap: wrap;
}
.nu_menu a,
.nu_menu .submenu-toggle {
display: block;
float: none;
}
.nu_menu li {
position: relative;
}
.nu_menu .has-submenu {
display: flex;
/* link and chevron button side by side */
}
.submenu {
position: absolute;
top: 100%;
left: 0;
min-width: 240px;
background: var(--cc-teal-dark);
box-shadow: 0 4px 8px rgba(0, 0, 0, .25);
z-index: 50;
}
.submenu a {
margin: 0;
padding: 12px 30px !important;
border-right: 0;
border-top: 1px solid var(--cc-teal-darker);
white-space: nowrap;
}
}
/* ### Mobile: toggle on the right of the header, dropdown under the header ### */
@media (max-width: 1023px) {
/* wrapper no longer positions anything, so the header is the containing block */
#cc_menu_nav {
position: static;
display: block;
width: auto;
min-height: 0;
background: transparent;
border-top: 0;
}
.menu-toggle {
display: block;
position: absolute;
right: 15px;
bottom: 20px;
height: 50px;
width: 50px;
z-index: 100;
}
.gi-sitelogo__image {
margin-bottom: 10px;
vertical-align: top;
/* removes the small inline gap so the toggle lines up */
}
.nu_menu {
display: none;
position: absolute;
top: 100%;
/* directly under the header */
left: 0;
right: 0;
float: none !important;
width: 100% !important;
box-shadow: 0 4px 8px rgba(0, 0, 0, .25);
z-index: 99;
}
.nu_menu.is-open {
display: block;
}
.nu_menu a {
display: block;
float: none;
margin: 0;
padding: 16px 20px !important;
border-right: 0;
border-bottom: 1px solid var(--cc-teal-darker);
font-size: 1.1em;
}
/* submenu = accordion: link on the left, chevron button on the right */
.nu_menu .has-submenu {
display: flex;
flex-wrap: wrap;
}
.nu_menu .submenu-link {
flex: 1;
padding-right: 20px !important;
}
.nu_menu .submenu-toggle {
flex: 0 0 60px;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
padding: 0;
border-right: 0;
border-left: 1px solid var(--cc-teal-darker);
border-bottom: 1px solid var(--cc-teal-darker);
}
.submenu {
flex-basis: 100%;
background: var(--cc-teal-darker);
}
.nu_menu .submenu a {
padding-left: 40px !important;
border-bottom-color: var(--cc-teal-dark);
}
/* stop the utilities bar overlapping the toggle */
.header__utilities {
position: static;
}
ol.utilitymenu.utilitymenu--top {
justify-content: flex-end;
margin-bottom: 10px;
}
}
@media (max-width: 1000px) {
.header__actions {
padding: 0
}
.header__actions .container {
padding: 0
}
.gi-breadcrumb__item {
min-width: fit-content
}
.gi-breadcrumb__list {
padding: 0 10px
}
ol.gi-breadcrumb__list {
display: flex;
width: max-content;
position: absolute;
max-width: 100vw;
overflow: scroll;
height: 50px;
overflow-y: clip;
overflow-x: auto
}
.utilitymenu--top .utilitymenu__item {
padding: 3px
}
}
/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
.nu_menu a,
.nu_menu .submenu-toggle::after {
transition: none;
}
}
<script>
(function () {
var toggle = document.querySelector('.menu-toggle');
var glyph = toggle.querySelector('span');
var nav = document.getElementById('main-nav');
var subToggles = nav.querySelectorAll('.submenu-toggle');
var desktop = window.matchMedia('(min-width: 1024px)');
function setSub(btn, open) {
btn.setAttribute('aria-expanded', open);
document.getElementById(btn.getAttribute('aria-controls')).hidden = !open;
}
function closeSubs(except) {
subToggles.forEach(function (b) { if (b !== except) setSub(b, false); });
}
function setOpen(open) {
nav.classList.toggle('is-open', open);
toggle.setAttribute('aria-expanded', open);
glyph.textContent = open ? '✕' : '☰'; // ✕ / ☰
if (!open) closeSubs();
}
// Mobile toggle
toggle.addEventListener('click', function () {
setOpen(!nav.classList.contains('is-open'));
});
// Submenu buttons (flyout on desktop, accordion on mobile)
subToggles.forEach(function (btn) {
btn.addEventListener('click', function () {
var open = btn.getAttribute('aria-expanded') !== 'true';
if (desktop.matches) closeSubs(btn); // one flyout at a time on desktop
setSub(btn, open);
});
});
// Selecting a link closes the menu (and any open submenu)
nav.addEventListener('click', function (e) {
if (e.target.closest('a')) setOpen(false);
});
// Escape: close submenu first (focus back to its button), else the mobile menu
document.addEventListener('keydown', function (e) {
if (e.key !== 'Escape') return;
var openSub = nav.querySelector('.submenu-toggle[aria-expanded="true"]');
if (openSub && openSub.parentNode.contains(document.activeElement)) {
setSub(openSub, false);
openSub.focus();
} else if (nav.classList.contains('is-open')) {
setOpen(false);
toggle.focus();
} else {
closeSubs();
}
});
// Desktop: close a flyout when focus leaves it or the user clicks elsewhere
nav.addEventListener('focusout', function (e) {
var li = e.target.closest('.has-submenu');
if (desktop.matches && li && e.relatedTarget && !li.contains(e.relatedTarget)) {
setSub(li.querySelector('.submenu-toggle'), false);
}
});
document.addEventListener('click', function (e) {
if (desktop.matches && !e.target.closest('.has-submenu')) closeSubs();
});
// Reset when crossing the breakpoint
desktop.addEventListener('change', function () { setOpen(false); });
})();
</script>
Working Example
Skip to main contentPage title
Content is centered with a max-width of 1500px.
Please note for the icons to work you must create a font awesome kit (opens in a new tab) and include the file in the header.