How to embed custom code blocks on Teachable
Custom code blocks can be embedded in Teachable lessons using the HTML/Embed block feature in the course editor. You can add syntax-highlighted code snippets, interactive code demos, or external code playground embeds through the content editor's HTML block functionality.
Prerequisites
- Access to Teachable course admin dashboard
- Basic HTML/CSS knowledge
- Course content editing permissions
- Understanding of iframe and embed concepts
Step-by-Step Instructions
Access your course lesson editor
Add an HTML/Embed content block
Insert basic code block HTML
<div class="code-block">
<pre><code>
// Your code here
function example() {
return 'Hello World';
}
</code></pre>
</div>Replace the sample code with your actual code content.
Add syntax highlighting with Prism.js
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" rel="stylesheet" />
<pre><code class="language-javascript">
// Your JavaScript code here
</code></pre>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script>Embed interactive code playgrounds
<iframe height="400" style="width: 100%;" scrolling="no" title="Code Example" src="https://codepen.io/username/embed/xxxxxx?height=400&theme-id=dark&default-tab=js,result" frameborder="no" allowtransparency="true" allowfullscreen="true"></iframe>Replace the src URL with your actual CodePen, JSFiddle, or Repl.it embed URL.
Style your code blocks with custom CSS
<style>
.code-block {
background-color: #f8f8f8;
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
margin: 10px 0;
overflow-x: auto;
}
.code-block pre {
margin: 0;
font-family: 'Courier New', monospace;
}
</style>Preview and publish your lesson
Common Issues & Troubleshooting
Code block not displaying with proper formatting
Ensure you're using proper <pre> and <code> HTML tags and check that special characters are properly encoded using HTML entities.
Syntax highlighting not working
Verify that Prism.js CSS and JavaScript files are properly linked and that you're using the correct language class (e.g., language-javascript) on your code elements.
Interactive code playground iframe not loading
Check that the embed URL is correct and that the external service (CodePen, JSFiddle) allows iframe embedding. Some services require specific embed URLs rather than direct page URLs.
Code block not responsive on mobile devices
Add overflow-x: auto to your CSS and ensure iframe elements have width: 100% and appropriate max-width settings for mobile compatibility.