All things Shopify and commerce
Can anyone help me tidy up an code error I'm getting in the theme.liquid of the site I'm building?
It's at the bottom and saying 'Attempting to close HtmlElement 'body' before HtmlElement 'style' was closed.
Screenshots attached. URL is https://flippin-tables-rubs.myshopify.com/
password skahmo
Solved! Go to the solution
This is an accepted solution.
Hey @SassInnes
This error typically occurs when the HTML structure in your theme.liquid file is not correctly nested, i.e., a </body> tag is closed before a </style> tag that should have been closed earlier. This breaks the HTML structure and can cause issues in rendering the page.
Here’s how the bottom of your theme.liquid file should look:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Shopify Store</title>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to My Store</h1>
<!-- Other content -->
</body>
</html>
Also Search for Unintended Code Injection: If you're dynamically injecting code via Liquid, ensure no unclosed <style> tags are added.
{% if some_condition %}
<style>
.custom-class {
color: red;
}
</style>
{% endif %}
It will cause the error if you have below coding structure.
<body>
<style>
/* Styles here */
</body>
</style>
Fix the Code Ensure the <style> tag or any other tag which is properly closed before closing the <body> tag.
This is an accepted solution.
Hey @SassInnes
This error typically occurs when the HTML structure in your theme.liquid file is not correctly nested, i.e., a </body> tag is closed before a </style> tag that should have been closed earlier. This breaks the HTML structure and can cause issues in rendering the page.
Here’s how the bottom of your theme.liquid file should look:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Shopify Store</title>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to My Store</h1>
<!-- Other content -->
</body>
</html>
Also Search for Unintended Code Injection: If you're dynamically injecting code via Liquid, ensure no unclosed <style> tags are added.
{% if some_condition %}
<style>
.custom-class {
color: red;
}
</style>
{% endif %}
It will cause the error if you have below coding structure.
<body>
<style>
/* Styles here */
</body>
</style>
Fix the Code Ensure the <style> tag or any other tag which is properly closed before closing the <body> tag.
thank you! that worked 🙂
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025