<div class="input-group">
<input type="text" value="https://codeshack.io/input-with-action-button/" readonly>
<button class="action-btn">
<span class="btn-text">Copy</span>
<svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
</button>
</div>
* { box-sizing: border-box; }
body {
font-family: system-ui, "Segoe UI", sans-serif;
background: #f1f5f9;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.input-group {
position: relative;
width: 320px;
display: flex;
align-items: center;
}
.input-group input {
width: 100%;
padding: 12px 16px;
padding-right: 90px; /* Space for button */
border: 1px solid #cbd5e1;
border-radius: 10px;
font-size: 1rem;
color: #334155;
outline: none;
background: white;
transition: border-color 0.2s;
}
.input-group input:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.action-btn {
position: absolute;
right: 6px;
top: 6px;
bottom: 6px;
background: #f1f5f9;
border: none;
border-radius: 6px;
padding: 0 12px;
cursor: pointer;
color: #0f172a;
font-weight: 600;
font-size: 0.85rem;
display: flex;
align-items: center;
gap: 6px;
transition: background 0.2s;
}
.action-btn:hover {
background: #e2e8f0;
}
.action-btn svg { opacity: 0.7; }