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 🙂
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024