Certainly! Below is a simple demo of a sleek, dark-themed web application interface featuring:
- Header: Displays the app's name.
- Main Content Area: Split into two sections:
- Code Editor: A textarea on the left side where users can write code.
- Preview: A live preview area on the right side that renders the written code.
This implementation uses HTML, CSS, and a bit of JavaScript to update the preview in real-time. You can copy the following code into a single HTML file and open it in your browser to see it in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dark Code Previewer</title>
<style>
/* Reset some default styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #1e1e1e;
color: #cccccc;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
height: 100vh;
display: flex;
flex-direction: column;
}
header {
background-color: #252526;
padding: 15px 20px;
text-align: center;
font-size: 1.5rem;
font-weight: bold;
border-bottom: 1px solid #333;
}
.container {
flex: 1;
display: flex;
overflow: hidden;
}
.editor, .preview {
flex: 1;
padding: 20px;
overflow: auto;
}
.editor {
background-color: #1e1e1e;
border-right: 1px solid #333;
}
.editor textarea {
width: 100%;
height: 100%;
background-color: #1e1e1e;
color: #cccccc;
border: none;
resize: none;
font-family: 'Courier New', Courier, monospace;
font-size: 1rem;
outline: none;
}
.preview {
background-color: #2d2d2d;
}
/* Scrollbar styling for WebKit */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #1e1e1e;
}
::-webkit-scrollbar-thumb {
background-color: #555;
border-radius: 4px;
}
/* Responsive Design */
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.editor {
border-right: none;
border-bottom: 1px solid #333;
}
}
</style>
</head>
<body>
<header>Dark Code Previewer</header>
<div class="container">
<div class="editor">
<textarea id="code" placeholder="Type your HTML code here...">
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #fff;
color: #000;
padding: 20px;
}
h1 { color: #3498db; }
</style>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a live preview.</p>
</body>
</html>
</textarea>
</div>
<div class="preview">
<iframe id="previewFrame" srcdoc="" frameborder="0" style="width: 100%; height: 100%; background-color: transparent;"></iframe>
</div>
</div>
<script>
const textarea = document.getElementById('code');
const previewFrame = document.getElementById('previewFrame');
function updatePreview() {
const code = textarea.value;
previewFrame.srcdoc = code;
}
// Initialize preview
updatePreview();
// Update preview on input with a slight debounce
let timeout;
textarea.addEventListener('input', () => {
clearTimeout(timeout);
timeout = setTimeout(updatePreview, 300);
});
</script>
</body>
</html>
Explanation of the Components
-
HTML Structure:
<header>: Contains the application's name, "Dark Code Previewer".
<div class="container">: Flex container that holds both the editor and preview sections.
<div class="editor">: Contains a <textarea> where users can input their HTML/CSS code.
<div class="preview">: Contains an <iframe> that renders the HTML/CSS code from the editor in real-time.
-
CSS Styling:
- Dark Theme: Utilizes dark background colors (
#1e1e1e, #252526, #2d2d2d) with light text (#cccccc).
- Layout: Uses Flexbox to arrange the editor and preview side by side. On smaller screens (max-width: 768px), it stacks them vertically for responsiveness.
- Scrollbar Styling: Customizes the scrollbar to match the dark theme.
- Typography: Uses monospaced font for the textarea to mimic a code editor feel.
-
JavaScript Functionality:
- Listens for input events on the textarea.
- Updates the
srcdoc of the iframe to reflect the current code in the textarea.
- Implements a debounce mechanism to prevent excessive updates while the user is typing.
Customization Options
-
Syntax Highlighting: For a more advanced code editor with syntax highlighting, consider integrating libraries like CodeMirror or Monaco Editor.
-
Additional Panes: You can extend this interface by adding separate panes for CSS and JavaScript, enabling more modular code editing.
-
Theming: Modify the CSS to customize colors, fonts, and other styling aspects to better fit your desired aesthetic.
Running the Demo
-
Copy the Code: Copy the entire HTML code provided above.
-
Create an HTML File: Open your preferred text editor and create a new file named index.html.
-
Paste and Save: Paste the copied code into index.html and save the file.
-
Open in Browser: Double-click the index.html file or open it using your web browser to see the dark-themed code editor and live preview in action.
Feel free to modify and expand upon this basic setup to suit your specific needs!