If you need more control over how your content looks or want to add custom code, switching to HTML view in WordPress is the way to go. It allows you to directly edit the structure of your content and add things like embeds, tracking codes, or custom styles.
In this article, I’ll explain how to switch to HTML view in both the Block Editor (Gutenberg) and the Classic Editor.
How to Switch to HTML View in Gutenberg
Gutenberg Editor, introduced in WordPress 5.0, allows you to create content using blocks. You can switch individual blocks to HTML view or switch the entire page. Here’s how.
Switching Individual Blocks to HTML View
- Log in to your WordPress dashboard.
- Go to Posts > All Posts or Pages > All Pages.
- Select the post or page you want to edit by clicking Edit.
- Click on the block you want to switch to HTML.
- Click the three dots (Options) at the top of the block toolbar.
- Select Edit as HTML from the dropdown menu.
This will convert the selected block to HTML view, allowing you to change its code.
Switching the Entire Page to HTML View
- Log in to your WordPress dashboard and open the post or page you want to modify.
- Click the three dots in the top-right corner of the Block Editor (next to the gear icon).
- Select Code Editor from the dropdown menu.
You will now see the entire page’s content in HTML format. To return to the normal view, click the three dots again and select Visual Editor.
How to Switch to HTML View in the Classic Editor
The Classic Editor presents your content in a box with two tabs: Visual and Text. If your site uses the Classic Editor plugin or if you haven’t switched to the Block Editor, follow these steps:
- Log in to your WordPress dashboard.
- Go to Posts > All Posts or Pages > All Pages.
- Click Edit under the post or page you want to modify.
- Click the Text tab (next to the Visual tab) in the editor.
This will switch the editor to HTML view, where you can see your content’s raw HTML code. To return to the regular editor, simply click the Visual tab.
Tips for Working in HTML View
Editing in HTML view requires attention to detail. Here are some practical tips to avoid issues:
- Don’t delete important tags. Tags like <div>, <p>, and <h1> structure your content and ensure it displays properly.
- Preview changes before publishing. This ensures everything looks the way you intended and no HTML errors are present.
- Use valid HTML syntax. Always close your tags (e.g., <div> and </div>) to avoid broken layouts.
- Add custom styles or scripts carefully. Use CSS within <style> tags and JavaScript inside <script> tags if needed.
Examples of Practical Uses for HTML View
Switching to HTML view isn’t just for developers—it’s useful for many common tasks. Here are some examples where switching to HTML view comes in handy:
- Embedding videos from third-party sources:
While the Block Editor has an embed block, some platforms provide code snippets that need to be pasted directly into the HTML view. Example: <iframe> tags for YouTube videos. - Adding tracking codes:
For example, insert a Facebook Pixel or Google Analytics tracking script. These scripts go inside the HTML view to ensure they function correctly on your page. - Fixing formatting issues:
If the visual editor adds extra spacing or alignment problems, switching to HTML view allows you to fine-tune the structure of your content. - Embedding forms:
Many services like Google Forms or Mailchimp provide embed code that works best when added via HTML view.
Troubleshooting Common HTML View Issues
Here are some common problems you may encounter while using HTML view, along with ways to fix them:
- HTML tags not showing correctly:
WordPress automatically removes certain HTML tags (like <script> or <iframe>) for security reasons. You can use plugins like Code Snippets to add these codes safely. - Code not displaying as expected:
Double-check your syntax. A single missing closing tag can break the entire layout. - Changes not saving properly:
If you switch between the visual and HTML views too often, some code might get removed or altered. Save your changes frequently and preview your page before publishing. - HTML editor option missing:
If you don’t see the HTML view option, make sure you are using the right editor. If you prefer using the old interface, the Classic Editor plugin may need to be installed.
Conclusion
Whether you use the Block Editor or the Classic Editor, knowing how to access and use HTML view helps you add custom elements, fix formatting issues, and ensure your content looks exactly how you want it. With the steps and tips outlined here, you’ll be comfortable switching between visual and HTML views, giving your site the flexibility it needs to stand out.